// TODO: Longer term we should read this from some config store, rather than a flag. // validateClusterIPFlags is expected to be called after Complete() funcvalidateClusterIPFlags(options *ServerRunOptions) []error { var errs []error
... // 省略
// note: While the cluster might be dualstack (i.e. pods with multiple IPs), the user may choose // to only ingress traffic within and into the cluster on one IP family only. this family is decided // by the range set on --service-cluster-ip-range. If/when the user decides to use dual stack services // the Secondary* must be of different IPFamily than --service-cluster-ip-range if secondaryServiceClusterIPRangeUsed { // Should be dualstack IPFamily(PrimaryServiceClusterIPRange) != IPFamily(SecondaryServiceClusterIPRange) dualstack, err := netutils.IsDualStackCIDRs([]*net.IPNet{&options.PrimaryServiceClusterIPRange, &options.SecondaryServiceClusterIPRange}) if err != nil { errs = append(errs, errors.New("error attempting to validate dualstack for --service-cluster-ip-range and --secondary-service-cluster-ip-range")) }
if !dualstack { errs = append(errs, errors.New("--service-cluster-ip-range and --secondary-service-cluster-ip-range must be of different IP family")) }
// should be smallish sized cidr, this thing is kept in etcd // bigger cidr (specially those offered by IPv6) will add no value // significantly increase snapshotting time. var ones, bits = options.SecondaryServiceClusterIPRange.Mask.Size() if bits-ones > 20 { errs = append(errs, errors.New("specified --secondary-service-cluster-ip-range is too large")) } }
return errs }
Calico
Edit the CNI config (calico-config ConfigMap in the manifest), and enable IPv4 and IPv6 address allocation by setting both fields to true.
# Source: calico/templates/calico-config.yaml # This ConfigMap is used to configure a self-hosted Calico installation. kind:ConfigMap apiVersion:v1 metadata: name:calico-config namespace:kube-system data: # Typha is disabled. typha_service_name:"none" # Configure the backend to use. calico_backend:"bird" # Configure the MTU to use for workload interfaces and tunnels. # - If Wireguard is enabled, set to your network MTU - 60 # - Otherwise, if VXLAN or BPF mode is enabled, set to your network MTU - 50 # - Otherwise, if IPIP is enabled, set to your network MTU - 20 # - Otherwise, if not using any encapsulation, set to your network MTU. veth_mtu:"1440"
# The CNI network configuration to install on each node. The special # values in this config will be automatically populated. cni_network_config:|- { "name":"k8s-pod-network", "cniVersion":"0.3.1", "plugins": [ { "type":"calico", "log_level":"info", "datastore_type":"kubernetes", "nodename":"__KUBERNETES_NODE_NAME__", "mtu":__CNI_MTU__, "ipam": { "type":"calico-ipam", "assign_ipv4":"true", "assign_ipv6":"true" }, "policy": { "type":"k8s" }, "kubernetes": { "kubeconfig":"__KUBECONFIG_FILEPATH__" } }, { "type":"portmap", "snat":true, "capabilities": {"portMappings":true} }, { "type":"bandwidth", "capabilities": {"bandwidth":true} } ] }
Configure IPv6 support by adding the following variable settings to the environment for the calico-node container