flannel-io / flannel

flannel is a network fabric for containers, designed for Kubernetes
Apache License 2.0
8.6k stars 2.87k forks source link

Configure IPv4/IPv6 dual-stack #1985

Open wuyanfeiwork opened 1 month ago

wuyanfeiwork commented 1 month ago

I need to configure flannel for dual-stack mode, my Kubernetes has been initialized for dual-stack mode, below is my kubeadm-config.yaml file:

---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
networking:
  podSubnet: 2001:db8:42:0::/56,10.244.0.0/16
  serviceSubnet: 2001:db8:42:1::/112,10.96.0.0/16
imageRepository: "localhost:5000"
kubernetesVersion: "1.25.4"
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: "2408:4002:116a:0:6c2a:43c9:80c0:6664"
  bindPort: 6443
nodeRegistration:
  kubeletExtraArgs:
    node-ip: 2408:4002:116a:0:6c2a:43c9:80c0:6664,192.168.0.1

I need the communication within the cluster to prioritize using IPv6, so I put the IPv6 address before the IPv4 address.

Below are the network-related configurations for flannel:

  net-conf.json: |
    {
      "EnableIPv6": true,
      "IPv6Network": "2001:db8:42:0::/56",
      "EnableIPv4": true,
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan"
      }
    }

The error message when starting flannel is as follows:

image

I don’t understand why it prompts: Observed a panic: Address is not an IPv4 address.

My server has both IPv4 and IPv6 addresses:

image

I changed EnableIPv4 to false, and Flannel can start normally.

But my requirement is to support both IPv4 and IPv6, with communication between Pods and Nodes prioritizing IPv6.

wuyanfeiwork commented 1 month ago
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
networking:
  podSubnet: 10.244.0.0/16,2001:db8:42:0::/56
  serviceSubnet: 2001:db8:42:1::/112,10.96.0.0/16
imageRepository: "localhost:5000"
kubernetesVersion: "1.25.4"
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: "2408:4002:116a:0:6c2a:43c9:80c0:6664"
  bindPort: 6443
nodeRegistration:
  kubeletExtraArgs:
    node-ip: 2408:4002:116a:0:6c2a:43c9:80c0:6664,192.168.0.1

I reset the Kubernetes cluster, and then moved the IPv4 address in the podSubnet parameter of the kubeadm-config.yaml file, 10.244.0.0/16, to the front, ahead of the IPv6 address 2001:db8:42:0::/56, and re-initialized the Kubernetes cluster. Now flannel starts up normally.

I don’t quite understand why this is?

rbrtbnfgl commented 3 weeks ago

Is it prioritizing the IPv6? I tried to read the logs and it's strange that you didn't get the IPv4 there; it should get both IPs independently from the order. To prioritize IPv6 I think that it's enough the order of node-ip on the Kubelet args.