Wire a Service's ports

  • 13 min
  • 6 steps
  • Networking

Steps

0 of 6 done

Fix a Service that sends traffic to the wrong port, add a second port, then expose the same pods as a NodePort and as a headless Service.

  1. Step 1 of 6

    kubectl exec client -- curl -sS -m 2 http://shop fails, although the shop pods are Running and Ready. Compare the port the Service forwards to with the port the container listens on.

    Checked against what your commands print.

  2. Step 2, not started: Point the Service at the container's port by its name, so that the Service keeps working if the image moves to another port number.

  3. Step 3, not started: Add a second port to shop: port 9090, named metrics, forwarding to 9090 on the pods. The API server rejects the first attempt most people make; read what it asks for.

  4. Step 4, not started: Create a second Service, shop-nodeport, that exposes the same pods on port 30080 of every node. Prove it from client through the address of kx-worker2.

  5. Step 5, not started: Create shop-headless, a Service for the same pods that gets no cluster IP, so a DNS lookup of its name returns the pod addresses.

  6. Step 6, not started: Ask the proxies to prefer shop endpoints in the client's own zone when there are any.

Lab terminal

Cluster time 50 seconds
kind cluster kx, Kubernetes 1.37.
Each step is checked as you work.
​
Tab completes. Up and Down recall.
Type help for more.
Terminal keys

Enter runs the command. Tab completes, and the arrow keys recall earlier commands. Control C stops a watch. On an empty line, or after Escape, Tab moves focus out of the terminal.