You are viewing documentation for Kubernetes version: v1.32
Kubernetes v1.32 documentation is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date information, see the latest version.
IPv4/IPv6 dual-stack
Kubernetes v1.23 [stable]IPv4/IPv6 dual-stack networking enables the allocation of both IPv4 and IPv6 addresses to Pods and Services.
IPv4/IPv6 dual-stack networking is enabled by default for your Kubernetes cluster starting in 1.21, allowing the simultaneous assignment of both IPv4 and IPv6 addresses.
Supported Features
IPv4/IPv6 dual-stack on your Kubernetes cluster provides the following features:
- Dual-stack Pod networking (a single IPv4 and IPv6 address assignment per Pod)
- IPv4 and IPv6 enabled Services
- Pod off-cluster egress routing (eg. the Internet) via both IPv4 and IPv6 interfaces
Prerequisites
The following prerequisites are needed in order to utilize IPv4/IPv6 dual-stack Kubernetes clusters:
- Kubernetes 1.20 or later - For information about using dual-stack services with earlier Kubernetes versions, refer to the documentation for that version of Kubernetes. 
- Provider support for dual-stack networking (Cloud provider or otherwise must be able to provide Kubernetes nodes with routable IPv4/IPv6 network interfaces) 
- A network plugin that supports dual-stack networking. 
Configure IPv4/IPv6 dual-stack
To configure IPv4/IPv6 dual-stack, set dual-stack cluster network assignments:
- kube-apiserver:- --service-cluster-ip-range=<IPv4 CIDR>,<IPv6 CIDR>
 
- kube-controller-manager:- --cluster-cidr=<IPv4 CIDR>,<IPv6 CIDR>
- --service-cluster-ip-range=<IPv4 CIDR>,<IPv6 CIDR>
- --node-cidr-mask-size-ipv4|--node-cidr-mask-size-ipv6defaults to /24 for IPv4 and /64 for IPv6
 
- kube-proxy:- --cluster-cidr=<IPv4 CIDR>,<IPv6 CIDR>
 
- kubelet:- --node-ip=<IPv4 IP>,<IPv6 IP>- This option is required for bare metal dual-stack nodes (nodes that do not define a
cloud provider with the --cloud-providerflag). If you are using a cloud provider and choose to override the node IPs chosen by the cloud provider, set the--node-ipoption.
- (The legacy built-in cloud providers do not support dual-stack --node-ip.)
 
- This option is required for bare metal dual-stack nodes (nodes that do not define a
cloud provider with the 
 
Note:
An example of an IPv4 CIDR: 10.244.0.0/16 (though you would supply your own address range)
An example of an IPv6 CIDR: fdXY:IJKL:MNOP:15::/64 (this shows the format but is not a valid
address - see RFC 4193)
Services
You can create Services which can use IPv4, IPv6, or both.
The address family of a Service defaults to the address family of the first service cluster IP
range (configured via the --service-cluster-ip-range flag to the kube-apiserver).
When you define a Service you can optionally configure it as dual stack. To specify the behavior you want, you
set the .spec.ipFamilyPolicy field to one of the following values:
- SingleStack: Single-stack service. The control plane allocates a cluster IP for the Service, using the first configured service cluster IP range.
- PreferDualStack: Allocates both IPv4 and IPv6 cluster IPs for the Service when dual-stack is enabled. If dual-stack is not enabled or supported, it falls back to single-stack behavior.
- RequireDualStack: Allocates Service- .spec.clusterIPsfrom both IPv4 and IPv6 address ranges when dual-stack is enabled. If dual-stack is not enabled or supported, the Service API object creation fails.- Selects the .spec.clusterIPfrom the list of.spec.clusterIPsbased on the address family of the first element in the.spec.ipFamiliesarray.
 
- Selects the 
If you would like to define which IP family to use for single stack or define the order of IP
families for dual-stack, you can choose the address families by setting an optional field,
.spec.ipFamilies, on the Service.
Note:
The.spec.ipFamilies field is conditionally mutable: you can add or remove a secondary
IP address family, but you cannot change the primary IP address family of an existing Service.You can set .spec.ipFamilies to any of the following array values:
- ["IPv4"]
- ["IPv6"]
- ["IPv4","IPv6"](dual stack)
- ["IPv6","IPv4"](dual stack)
The first family you list is used for the legacy .spec.clusterIP field.
Dual-stack Service configuration scenarios
These examples demonstrate the behavior of various dual-stack Service configuration scenarios.
Dual-stack options on new Services
- This Service specification does not explicitly define - .spec.ipFamilyPolicy. When you create this Service, Kubernetes assigns a cluster IP for the Service from the first configured- service-cluster-ip-rangeand sets the- .spec.ipFamilyPolicyto- SingleStack. (Services without selectors and headless Services with selectors will behave in this same way.)- apiVersion: v1 kind: Service metadata: name: my-service labels: app.kubernetes.io/name: MyApp spec: selector: app.kubernetes.io/name: MyApp ports: - protocol: TCP port: 80
- This Service specification explicitly defines - PreferDualStackin- .spec.ipFamilyPolicy. When you create this Service on a dual-stack cluster, Kubernetes assigns both IPv4 and IPv6 addresses for the service. The control plane updates the- .specfor the Service to record the IP address assignments. The field- .spec.clusterIPsis the primary field, and contains both assigned IP addresses;- .spec.clusterIPis a secondary field with its value calculated from- .spec.clusterIPs.- For the .spec.clusterIPfield, the control plane records the IP address that is from the same address family as the first service cluster IP range.
- On a single-stack cluster, the .spec.clusterIPsand.spec.clusterIPfields both only list one address.
- On a cluster with dual-stack enabled, specifying RequireDualStackin.spec.ipFamilyPolicybehaves the same asPreferDualStack.
 - apiVersion: v1 kind: Service metadata: name: my-service labels: app.kubernetes.io/name: MyApp spec: ipFamilyPolicy: PreferDualStack selector: app.kubernetes.io/name: MyApp ports: - protocol: TCP port: 80
- For the 
- This Service specification explicitly defines - IPv6and- IPv4in- .spec.ipFamiliesas well as defining- PreferDualStackin- .spec.ipFamilyPolicy. When Kubernetes assigns an IPv6 and IPv4 address in- .spec.clusterIPs,- .spec.clusterIPis set to the IPv6 address because that is the first element in the- .spec.clusterIPsarray, overriding the default.- apiVersion: v1 kind: Service metadata: name: my-service labels: app.kubernetes.io/name: MyApp spec: ipFamilyPolicy: PreferDualStack ipFamilies: - IPv6 - IPv4 selector: app.kubernetes.io/name: MyApp ports: - protocol: TCP port: 80
Dual-stack defaults on existing Services
These examples demonstrate the default behavior when dual-stack is newly enabled on a cluster where Services already exist. (Upgrading an existing cluster to 1.21 or beyond will enable dual-stack.)
- When dual-stack is enabled on a cluster, existing Services (whether - IPv4or- IPv6) are configured by the control plane to set- .spec.ipFamilyPolicyto- SingleStackand set- .spec.ipFamiliesto the address family of the existing Service. The existing Service cluster IP will be stored in- .spec.clusterIPs.- apiVersion: v1 kind: Service metadata: name: my-service labels: app.kubernetes.io/name: MyApp spec: selector: app.kubernetes.io/name: MyApp ports: - protocol: TCP port: 80- You can validate this behavior by using kubectl to inspect an existing service. - kubectl get svc my-service -o yaml- apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/name: MyApp name: my-service spec: clusterIP: 10.0.197.123 clusterIPs: - 10.0.197.123 ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - port: 80 protocol: TCP targetPort: 80 selector: app.kubernetes.io/name: MyApp type: ClusterIP status: loadBalancer: {}
- When dual-stack is enabled on a cluster, existing headless Services with selectors are configured by the control plane to set - .spec.ipFamilyPolicyto- SingleStackand set- .spec.ipFamiliesto the address family of the first service cluster IP range (configured via the- --service-cluster-ip-rangeflag to the kube-apiserver) even though- .spec.clusterIPis set to- None.- apiVersion: v1 kind: Service metadata: name: my-service labels: app.kubernetes.io/name: MyApp spec: selector: app.kubernetes.io/name: MyApp ports: - protocol: TCP port: 80- You can validate this behavior by using kubectl to inspect an existing headless service with selectors. - kubectl get svc my-service -o yaml- apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/name: MyApp name: my-service spec: clusterIP: None clusterIPs: - None ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - port: 80 protocol: TCP targetPort: 80 selector: app.kubernetes.io/name: MyApp
Switching Services between single-stack and dual-stack
Services can be changed from single-stack to dual-stack and from dual-stack to single-stack.
- To change a Service from single-stack to dual-stack, change - .spec.ipFamilyPolicyfrom- SingleStackto- PreferDualStackor- RequireDualStackas desired. When you change this Service from single-stack to dual-stack, Kubernetes assigns the missing address family so that the Service now has IPv4 and IPv6 addresses.- Edit the Service specification updating the - .spec.ipFamilyPolicyfrom- SingleStackto- PreferDualStack.- Before: - spec: ipFamilyPolicy: SingleStack- After: - spec: ipFamilyPolicy: PreferDualStack
- To change a Service from dual-stack to single-stack, change - .spec.ipFamilyPolicyfrom- PreferDualStackor- RequireDualStackto- SingleStack. When you change this Service from dual-stack to single-stack, Kubernetes retains only the first element in the- .spec.clusterIPsarray, and sets- .spec.clusterIPto that IP address and sets- .spec.ipFamiliesto the address family of- .spec.clusterIPs.
Headless Services without selector
For Headless Services without selectors
and without .spec.ipFamilyPolicy explicitly set, the .spec.ipFamilyPolicy field defaults to
RequireDualStack.
Service type LoadBalancer
To provision a dual-stack load balancer for your Service:
- Set the .spec.typefield toLoadBalancer
- Set .spec.ipFamilyPolicyfield toPreferDualStackorRequireDualStack
Note:
To use a dual-stackLoadBalancer type Service, your cloud provider must support IPv4 and IPv6
load balancers.Egress traffic
If you want to enable egress traffic in order to reach off-cluster destinations (eg. the public Internet) from a Pod that uses non-publicly routable IPv6 addresses, you need to enable the Pod to use a publicly routed IPv6 address via a mechanism such as transparent proxying or IP masquerading. The ip-masq-agent project supports IP masquerading on dual-stack clusters.
Note:
Ensure your CNI provider supports IPv6.Windows support
Kubernetes on Windows does not support single-stack "IPv6-only" networking. However, dual-stack IPv4/IPv6 networking for pods and nodes with single-family services is supported.
You can use IPv4/IPv6 dual-stack networking with l2bridge networks.
Note:
Overlay (VXLAN) networks on Windows do not support dual-stack networking.You can read more about the different network modes for Windows within the Networking on Windows topic.