Score:0

How kubernetes can expose port when docker not allows exposing port after creation

gr flag

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

Nikita Kipriyanov avatar
za flag
Perhaps because Kubernets is not Docker? Why birds can fly while fish can not, although birds technically are very advanced fish?
signalz avatar
gr flag
can you consider the case where the kubernetes pods are docker based, not any other containerization solution.
Nikita Kipriyanov avatar
za flag
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.
pt flag
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.
Score:0
za flag

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]

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.