Namespace straits-128alob has a Deployment market-web with 3 replicas and a Pod named client running busybox.
kubectl get pods -n straits-128alob -o wideThree web Pods, three different IPs. Nothing in front of them yet.
Create the Service
expose reads the Deployment's selector and builds a Service around it:
kubectl expose deployment market-web --port=80 -n straits-128alob
kubectl get svc -n straits-128alob
kubectl describe svc market-web -n straits-128alobThe Service shows a CLUSTER-IP. The Endpoints: line of describe lists all three Pod IPs on port 80.
$ kubectl get svc -n straits-128alob
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
market-web ClusterIP 10.96.248.109 <none> 80/TCP 5s
$ kubectl get endpoints -n straits-128alob
NAME ENDPOINTS AGE
market-web 10.42.0.8:80,10.42.0.9:80,10.42.0.10:80 5sFetch the page by name
Run a command inside the client Pod. The name market-web resolves inside the cluster:
kubectl exec client -n straits-128alob -- wget -qO- market-webRead the <title> in the HTML that comes back. That is the answer to the last objective.
Watch the endpoints follow the Pods
kubectl delete pod -n straits-128alob -l app=market-web
kubectl get pods -n straits-128alob -o wide
kubectl describe svc market-web -n straits-128alobThe Deployment replaces the Pods, the Endpoints: line updates to the new IPs, and wget by name keeps working.