Dual-stack service question
Can someone explain the difference between PreferDualStack and RequireDualStack for ipFamilyPolicy? I don't really see the distinction between these from reading the docs. When I created two services using the different ipFamilyPolicy, I don't see a difference at all in the corresponding services.
# kubeadm describe svc prefer-ipv6-dualstack
Name: prefer-ipv6-dualstack
Namespace: sample-app
Labels: app=golang-http
Annotations: <none>
Selector: app=golang-http,deploymentconfig=golang-http,name=golang-http
Type: ClusterIP
IP Family Policy: PreferDualStack
IP Families: IPv6,IPv4
IP: fd02::8a12
IPs: fd02::8a12,172.31.239.195
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
Endpoints: [fd01:0:0:4::1d]:8080,[fd01:0:0:9::4e]:8080,[fd01:0:0:9::4f]:8080 + 2 more...
Session Affinity: None
Events: <none>
# kubeadm describe svc require-ipv6-dualstack
Name: require-ipv6-dualstack
Namespace: sample-app
Labels: app=golang-http
Annotations: <none>
Selector: app=golang-http,deploymentconfig=golang-http,name=golang-http
Type: ClusterIP
IP Family Policy: RequireDualStack
IP Families: IPv6,IPv4
IP: fd02::193d
IPs: fd02::193d,172.31.58.202
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
Endpoints: [fd01:0:0:4::1d]:8080,[fd01:0:0:9::4e]:8080,[fd01:0:0:9::4f]:8080 + 2 more...
Session Affinity: None
Events: <none>
https://kubernetes.io/docs/concepts/services-networking/dual-stack/
Posted May 18, 2022, 10:50 PM UTC
Unless there is a ipFamilyPolicy it will default to single stack. If ipFamilyPolicy is set to PreferDualStack the service will be created and will be dual stack if possible but not fail if one of the address families cannot be allocated. With RequireDualStack if both families cannot be allocated the service creation will fail.
The use cases here are mostly related to CNI's, kubeproxy and Service LoadBalancers, but your question is about Services and I'm one of the maintainers of PureLB and we added DualStack support last year (not sure about dual stack in the others). You can define the pools of addresses with IPv4, IPv6 or both. If you were to set RequireDualStack but reference a v4 or v6 only pool the service creation would fail, PreferDualStack would work but only allocate the family contained in the pool.
As it relates to CNI/kubeproxy, the logic is the similar. In more complex CNI's the address ranges can be defined by node groups and its possible to run singlestack only nodes v4 or v6, therefore logic is needed to select the right node.