In the ordinary course of events, Pods can be stopped accidentally. Then, the IP of the Pod can be changed. When we expose the port for a Pod or a Deployment, we create a Kubernetes Service that acts as a proxy or a load balancer. Kubernetes would create a virtual IP, which receives the request from clients and proxies the traffic to the Pods in a service. Let's review how to do this:
- First, we would create a Deployment and expose it to a Service:
$ cat nodeport-deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: nodeport-deployspec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: my-nginx image: nginx---apiVersion: v1kind: Service ...