containerPort
ContainerPort is a field used in container specifications within Kubernetes to declare the network port on which a container listens. It is defined inside a container’s ports section and is typically expressed as an integer value, often accompanied by an optional name. While not strictly required for a container to run, specifying containerPort helps with documentation, tooling, and integration with Kubernetes Services.
In a Pod specification, you may declare multiple containers, each with its own containerPort. A named port
This naming allows a Service to reference the port by name (targetPort: web) instead of a numeric
ContainerPort and Services: In Kubernetes, Services route traffic to Pods by selecting them and forwarding to
Difference from hostPort: containerPort is an internal port within the container’s network namespace. HostPort would expose
Best practices: declare containerPort when possible, use meaningful port names for easier service configuration, and ensure