Why do we need a port/containerPort in a Kuberntes deployment/container definition? Why do we need a port/containerPort in a Kuberntes deployment/container definition? kubernetes kubernetes

Why do we need a port/containerPort in a Kuberntes deployment/container definition?


As you quote the documentation,

List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network. Cannot be updated.

the purpose of defining the containerPorts is purely for documentation. It is only used by other developers to understand the port that the container listens to. Kubernetes borrows this idea from docker which does the same with EXPOSE command as mentioned here.