3.2.5 Publishing your Service

View in the book. Buy the book.

Exposing the Deployment to the internet.

Next, expose the service.

3.12 Relationship between the Service and the Pods it targets (selects)
Figure 3.12 Relationship between the Service and the Pods it targets (selects)

Create the service

cd Chapter03/3.2_DeployingToKubernetes
kubectl create -f service.yaml

View the status. It weill initially show as <pending>

$ kubectl get service
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      34.118.224.1     <none>        443/TCP        11h
timeserver   LoadBalancer   34.118.230.169   <pending>     80:31212/TCP   3s

You can watch for changes with -w, like:

$ kubectl get service -w
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      34.118.224.1     <none>        443/TCP        11h
timeserver   LoadBalancer   34.118.230.169   <pending>     80:31212/TCP   36s
timeserver   LoadBalancer   34.118.230.169   203.0.113.16  80:31212/TCP   44s

When you see the IP, you can test it:

$ curl http://203.0.113.16
The time is 7:01 PM, UTC.