Do you need to define ports.containerPort in K8s if Dockerfile describes as EXPOSE

9/19/2019

I have a legacy Deployment.yaml that is used by Helm and works fine so far.

      containers:
        ports:
          - containerPort: 3000

This part here was wrongly indended before. So the ports part of it wasn't active or used in k8s as far as I understand.

So what wonders me now is how the container was running and accessible at port 3000 the whole time? So I looked for another definition describing this port.

I found it in the Dockerfile

   EXPOSE 3000

My question is now - do you need to define port.containerPort in the .yaml configuration or is the container port already implied to be at 3000 through the Dockerfile's EXPOSE statement?

It feels like k8s knows that this should be the containerport since the Dockerfile describes it.

-- xetra11
docker
kubernetes
kubernetes-container

1 Answer

9/19/2019

NO, EXPOSE hat nothing to do with this, that only an Info for you that the container will use port 3000. the configuration is coming from containerPort

for k8s see this

for expose see this

-- LinPy
Source: StackOverflow