0

As far as i know, in docker you have to describe the ports that will be used on container while creating it, and you cannot add any other ports afterwards.

But as i see, in kubernetes you can "expose" the ports after the creation of the pods.

So while docker is not allowing it, how come kubernetes can do that ?

Thanks

  • 1
    Perhaps because Kubernets is not Docker? Why birds can fly while fish can not, although birds technically are very advanced fish? – Nikita Kipriyanov Jun 08 '23 at 10:03
  • can you consider the case where the kubernetes pods are docker based, not any other containerization solution. – signalz Jun 08 '23 at 11:47
  • 1
    Jokes aside, container archive is just a bunch of programs plus settings. There is nothing strictly "docker based". It can't decide anything. It can't forbid anything. It's runtime who decides what to do with these programs. There are some settings, but it's up to runtime to decide whether to override anything; you can override things even in docker, for example, start other entry point that was recorded; docker guys simply decided to not make "expose port" overridable in their runtime, while Kubernetes guys decided other way. – Nikita Kipriyanov Jun 08 '23 at 12:22
  • Kubernetes can expose ports after creation the same way *you* can do that using Docker -- by directly manipulating netfilter rules, rather than relying on Docker to do it. – larsks Jun 08 '23 at 15:16

1 Answers1

0

There are several ways to expose a port using a Service:

You can easily expose a deployment using the following command:

kubectl expose deploy nginx --port 80
kubectl port-forward service/nginx-service 8080:80
  • NodePort
  • LoadBalancer
  • Ingress

By the way, I believe this picture will help clarify the concept of NodePort for you. To understand other concepts, I recommend referring to the official Kubernetes guide.

My Github

[NodePort]