Services

Give a set of pods one stable address.

A Kubernetes practice simulator runs inside your browser tab. It behaves like the real commands for what the lessons teach, and it is labelled as a simulation.

Pods come and go; a service stays

Every pod has its own address, and that address changes whenever the pod is replaced. Other programs cannot rely on it.

A service gives a deployment one stable name and address, and spreads requests across its pods.

kubectl expose creates a service for a deployment. --port is the port the service listens on.

Example
kubectl create deployment web --image=nginx
kubectl expose deployment web --port=80
kubectl get services

Who can reach a service

The type of a service decides who can reach it. ClusterIP, the default, is reachable only from inside the cluster.

NodePort also opens a port on every machine of the cluster. LoadBalancer asks the cloud provider for an address on the internet.

If the program listens on a different port from the service, add --target-port.

Example
kubectl create deployment web --image=nginx
kubectl expose deployment web --port=80 --type=NodePort
kubectl get services

Your turn: an internal service

A deployment named api is running here.

Practice task

Create a service for the deployment api on port 8080, reachable only inside the cluster.

Your answer is run and checked in the lesson. Create a free account to try it.

Your turn: reach it from outside

A deployment named web is running here.

Practice task

Create a NodePort service for the deployment web on port 80.

Your answer is run and checked in the lesson. Create a free account to try it.