CertGrid CertGrid
Hands-on Lab·Certified Kubernetes Application Developer

Service Ports: port, targetPort and nodePort

Three numbers are involved in getting a request to a container - `port`, `targetPort` and `containerPort` - and only two of them matter. This proves which by setting `containerPort` to something completely wrong and watching everything keep working, then setting `targetPort` wrong and watching it all stop.

Services and Networking Guide 33 of 44 Beginner

Written against the versions above. `containerPort` is informational. It does not open, publish or reserve anything - the process listens on whatever it listens on. Its only real functions are documentation and giving the port a NAME that `targetPort` can refer to.

Two Deployments and a client Pod. Everything is ClusterIP traffic inside the cluster.
Server NameIP AddressOSRolesCPURAMHDD
CKA1001192.168.0.175Ubuntu 26.04 LTSControl Plane Node2 Core4 GB50 GB
CKA1001-NODE01192.168.0.176Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE02192.168.0.177Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE03192.168.0.178Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB

Before you start

  1. Three numbers that are not the same thing

  2. The wrong containerPort does not matter

  3. The wrong targetPort breaks everything

  4. Naming the port instead

Official sources