大部分情况下,不需要指定vip,因为内部pod通过域名的方式访问service,此处只是作为演示。
# svc-vip.yaml
apiVersion: v1
kind: Service
metadata:
name: slb-s2
namespace: default
spec:
selector:
app: nginx
release: stable
partition: website
tier: slb
clusterIP: 10.100.138.12
ports:
- name: http
port: 80
targetPort: 80
[root@maxiaoke nginx-01]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 13d
slb-s1 ClusterIP 10.100.138.11 <none> 80/TCP 64m
slb-s2 ClusterIP 10.100.138.12 <none> 80/TCP 7s
[root@maxiaoke nginx-01]# kubectl describe svc slb-s2
Name: slb-s2
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=nginx,partition=website,release=stable,tier=slb
Type: ClusterIP
IP Families: <none>
IP: 10.100.138.12
IPs: 10.100.138.12
Port: http 80/TCP
TargetPort: 80/TCP
Endpoints: 10.200.3.10:80,10.200.4.8:80,10.200.4.9:80 + 2 more...
Session Affinity: None
Events: <none>