Every Pod gets an IP from the cluster's Pod range. When the Pod goes, the IP goes with it.
text
10:00 market-web-7c-abc 10.42.0.8 Running
10:05 market-web-7c-abc deleted
10:05 market-web-7c-xyz 10.42.0.14 Running ← new Pod, new IPA client that wrote down 10.42.0.8 now talks to nothing. With three replicas and rolling updates, the list of IPs changes all day.
A Service stands in front
A Service is an object with a stable address and a label selector:
Service market-webone IP, one name, for ever
selector app=market-web
10.42.0.8 · 10.42.0.9 · 10.42.0.14whichever Pods match right now
| Part | Holds |
|---|---|
clusterIP | A virtual IP, allocated once, kept for the life of the Service |
selector | The labels of the Pods behind it |
ports | Which port clients use, and which port on the Pod it goes to |
The cluster also gives every Service a DNS name, so clients do not need the IP either. They say market-web, and a Pod with the right labels answers.
Make one
text
learner@shallows:~$ kubectl expose deployment market-web --port=80
service/market-web exposed
learner@shallows:~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
market-web ClusterIP 10.96.248.109 <none> 80/TCP 5sexpose reads the Deployment's Pod labels and builds a Service that selects them. svc is the short name.