2

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
  • 7,671
  • 14
  • 84
  • 159

1 Answers1

3

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
  • 16,987
  • 4
  • 43
  • 57
  • As I mentioned the indendation for the `ports` list in .yaml was wrongly formatted but the container was accessible still. How can you explain this? Default ports for containers aren't 3000 are they? Or did K8s repaired the .yaml by its own – xetra11 Sep 19 '19 at 07:16
  • 1
    if that is a real identaion error , then k8s will give you an error I think and refuse to start. – LinPy Sep 19 '19 at 07:18