kubernetes-sigs / kind

Kubernetes IN Docker - local clusters for testing Kubernetes
https://kind.sigs.k8s.io/
Apache License 2.0
13.36k stars 1.55k forks source link

How to fix the ip of a docker container created with the kind command? #3579

Closed Ghost-Cavendish closed 5 months ago

Ghost-Cavendish commented 5 months ago

How to fix the ip of a docker container created with the kind command?

aojea commented 5 months ago

kind depends on the backend docker/podman/nerdctl to handle the low level details, if you are more explicit about the exact problems we can try to help, but is not clear from the description what is the problem

Ghost-Cavendish commented 5 months ago

kind depends on the backend docker/podman/nerdctl to handle the low level details, if you are more explicit about the exact problems we can try to help, but is not clear from the description what is the problem

It is to configure a static IP for the k8s node created by kind, that is, how to make the docker container IP created by the kind command static, just like the docker-compose configuration in the following figure.

image

aojea commented 5 months ago

why do you need a static ip?

Ghost-Cavendish commented 5 months ago

why do you need a static ip?为什么需要静态IP?

I want to use a custom CNI network plugin, and I need to add a route to the container, otherwise the K8S multi-node pods cannot communicate with each other

Ghost-Cavendish commented 5 months ago

need to add a route to the container IP, so you need the container IP to be a static IP

stmcginnis commented 5 months ago

You shouldn't need a static IP for pods within the same cluster to communicate with each other. That is one of the the things the CNI should take care of for you.

aojea commented 5 months ago

I've presented in kubecon about this topic https://github.com/aojea/kind-networking-plugins , about using kind for advanced networking scenarios

Ghost-Cavendish commented 5 months ago

You shouldn't need a static IP for pods within the same cluster to communicate with each other. That is one of the the things the CNI should take care of for you.同一集群内的Pod之间不需要静态IP就可以进行通信。这是CNI应该为你照顾的事情之一。

I am using CNI is bridge, because there is no route that causes the pods on different worker nodes to not be able to communicate, why can't I configure the static IP is any difficulty

Ghost-Cavendish commented 5 months ago

https://github.com/kubernetes-sigs/kind/pull/3553 image

Isn't this PR just to implement this function, why didn't it pass

stmcginnis commented 5 months ago

Partly because this is something controlled by the container runtime. Any implementation would need to work with docker, podman, and nerdctl in a cleanly abstracted way.

Kind may not be the right tool for your use case right now. The docker network is responsible for assigning the IP address to the container. Assuming you don't run other containers and create a kind cluster in the same way, it's possible the pods will always get assigned the same IP addresses. But there are no guarantees.

aojea commented 5 months ago

same as this https://github.com/kubernetes-sigs/kind/issues/3580#issuecomment-2051784137 , networking is complex , it increase the surface of the project, it is different depending on the implementation of the containers runtimes, and for complex network scenarios it is better to follow my guidelines in https://github.com/kubernetes-sigs/kind/issues/3579#issuecomment-2054097386

BenTheElder commented 5 months ago

We don't support this and we don't plan to. (see https://github.com/kubernetes-sigs/kind/issues/3579#issuecomment-2054175737)