Skip to content

Commit 00c294a

Browse files
committed
Tweak two network tasks: validate-dual-stack and extend-service-ip-ranges
1 parent 07b93cb commit 00c294a

File tree

2 files changed

+77
-33
lines changed

2 files changed

+77
-33
lines changed

content/en/docs/tasks/network/extend-service-ip-ranges.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ This document shares how to extend the existing Service IP range assigned to a c
2424
## API
2525

2626
Kubernetes clusters with kube-apiservers that have enabled the `MultiCIDRServiceAllocator`
27-
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) and have the `networking.k8s.io/v1beta1`
28-
API group active,
29-
will create a ServiceCIDR object that takes the well-known name `kubernetes`, and that specifies an IP address range
27+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) and have the
28+
`networking.k8s.io/v1beta1` API group active, will create a ServiceCIDR object that takes
29+
the well-known name `kubernetes`, and that specifies an IP address range
3030
based on the value of the `--service-cluster-ip-range` command line argument to kube-apiserver.
3131

3232
```sh
3333
kubectl get servicecidr
3434
```
35+
3536
```
3637
NAME CIDRS AGE
3738
kubernetes 10.96.0.0/28 17d
@@ -44,6 +45,7 @@ cluster IP address.
4445
```sh
4546
kubectl get service kubernetes
4647
```
48+
4749
```
4850
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
4951
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 17d
@@ -54,26 +56,32 @@ The default Service, in this case, uses the ClusterIP 10.96.0.1, that has the co
5456
```sh
5557
kubectl get ipaddress 10.96.0.1
5658
```
59+
5760
```
5861
NAME PARENTREF
5962
10.96.0.1 services/default/kubernetes
6063
```
6164

62-
The ServiceCIDRs are protected with {{<glossary_tooltip text="finalizers" term_id="finalizer">}}, to avoid leaving Service ClusterIPs orphans;
63-
the finalizer is only removed if there is another subnet that contains the existing IPAddresses or
64-
there are no IPAddresses belonging to the subnet.
65+
The ServiceCIDRs are protected with {{<glossary_tooltip text="finalizers" term_id="finalizer">}},
66+
to avoid leaving Service ClusterIPs orphans; the finalizer is only removed if there is another subnet
67+
that contains the existing IPAddresses or there are no IPAddresses belonging to the subnet.
6568

6669
## Extend the number of available IPs for Services
6770

68-
There are cases that users will need to increase the number addresses available to Services, previously, increasing the Service range was a disruptive operation that could also cause data loss. With this new feature users only need to add a new ServiceCIDR to increase the number of available addresses.
71+
There are cases that users will need to increase the number addresses available to Services,
72+
previously, increasing the Service range was a disruptive operation that could also cause data loss.
73+
With this new feature users only need to add a new ServiceCIDR to increase the number of available addresses.
6974

7075
### Adding a new ServiceCIDR
7176

72-
On a cluster with a 10.96.0.0/28 range for Services, there is only 2^(32-28) - 2 = 14 IP addresses available. The `kubernetes.default` Service is always created; for this example, that leaves you with only 13 possible Services.
77+
On a cluster with a 10.96.0.0/28 range for Services, there is only 2^(32-28) - 2 = 14
78+
IP addresses available. The `kubernetes.default` Service is always created; for this example,
79+
that leaves you with only 13 possible Services.
7380

7481
```sh
7582
for i in $(seq 1 13); do kubectl create service clusterip "test-$i" --tcp 80 -o json | jq -r .spec.clusterIP; done
7683
```
84+
7785
```
7886
10.96.0.11
7987
10.96.0.5
@@ -104,6 +112,7 @@ spec:
104112
- 10.96.0.0/24
105113
EOF
106114
```
115+
107116
```
108117
servicecidr.networking.k8s.io/newcidr1 created
109118
```
@@ -113,6 +122,7 @@ and this will allow you to create new Services with ClusterIPs that will be pick
113122
```sh
114123
for i in $(seq 13 16); do kubectl create service clusterip "test-$i" --tcp 80 -o json | jq -r .spec.clusterIP; done
115124
```
125+
116126
```
117127
10.96.0.48
118128
10.96.0.200
@@ -127,6 +137,7 @@ You cannot delete a ServiceCIDR if there are IPAddresses that depend on the Serv
127137
```sh
128138
kubectl delete servicecidr newcidr1
129139
```
140+
130141
```
131142
servicecidr.networking.k8s.io "newcidr1" deleted
132143
```
@@ -136,7 +147,8 @@ Kubernetes uses a finalizer on the ServiceCIDR to track this dependent relations
136147
```sh
137148
kubectl get servicecidr newcidr1 -o yaml
138149
```
139-
```
150+
151+
```yaml
140152
apiVersion: networking.k8s.io/v1beta1
141153
kind: ServiceCIDR
142154
metadata:
@@ -161,12 +173,12 @@ status:
161173
type: Ready
162174
```
163175
164-
165176
By removing the Services containing the IP addresses that are blocking the deletion of the ServiceCIDR
166177
167178
```sh
168179
for i in $(seq 13 16); do kubectl delete service "test-$i" ; done
169180
```
181+
170182
```
171183
service "test-13" deleted
172184
service "test-14" deleted
@@ -180,6 +192,7 @@ so that the ServiceCIDR that was pending deletion will actually be removed.
180192
```sh
181193
kubectl get servicecidr newcidr1
182194
```
195+
183196
```
184197
Error from server (NotFound): servicecidrs.networking.k8s.io "newcidr1" not found
185198
```

content/en/docs/tasks/network/validate-dual-stack.md

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ content_type: task
1111
<!-- overview -->
1212
This document shares how to validate IPv4/IPv6 dual-stack enabled Kubernetes clusters.
1313

14-
1514
## {{% heading "prerequisites" %}}
1615

17-
18-
* Provider support for dual-stack networking (Cloud provider or otherwise must be able to provide Kubernetes nodes with routable IPv4/IPv6 network interfaces)
19-
* A [network plugin](/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/) that supports dual-stack networking.
16+
* Provider support for dual-stack networking (Cloud provider or otherwise must be able to
17+
provide Kubernetes nodes with routable IPv4/IPv6 network interfaces)
18+
* A [network plugin](/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/)
19+
that supports dual-stack networking.
2020
* [Dual-stack enabled](/docs/concepts/services-networking/dual-stack/) cluster
2121

2222
{{< version-check >}}
@@ -25,29 +25,36 @@ This document shares how to validate IPv4/IPv6 dual-stack enabled Kubernetes clu
2525
While you can validate with an earlier version, the feature is only GA and officially supported since v1.23.
2626
{{< /note >}}
2727

28-
2928
<!-- steps -->
3029

3130
## Validate addressing
3231

3332
### Validate node addressing
3433

35-
Each dual-stack Node should have a single IPv4 block and a single IPv6 block allocated. Validate that IPv4/IPv6 Pod address ranges are configured by running the following command. Replace the sample node name with a valid dual-stack Node from your cluster. In this example, the Node's name is `k8s-linuxpool1-34450317-0`:
34+
Each dual-stack Node should have a single IPv4 block and a single IPv6 block allocated.
35+
Validate that IPv4/IPv6 Pod address ranges are configured by running the following command.
36+
Replace the sample node name with a valid dual-stack Node from your cluster. In this example,
37+
the Node's name is `k8s-linuxpool1-34450317-0`:
3638

3739
```shell
3840
kubectl get nodes k8s-linuxpool1-34450317-0 -o go-template --template='{{range .spec.podCIDRs}}{{printf "%s\n" .}}{{end}}'
3941
```
42+
4043
```
4144
10.244.1.0/24
4245
2001:db8::/64
4346
```
47+
4448
There should be one IPv4 block and one IPv6 block allocated.
4549

46-
Validate that the node has an IPv4 and IPv6 interface detected. Replace node name with a valid node from the cluster. In this example the node name is `k8s-linuxpool1-34450317-0`:
50+
Validate that the node has an IPv4 and IPv6 interface detected.
51+
Replace node name with a valid node from the cluster.
52+
In this example the node name is `k8s-linuxpool1-34450317-0`:
4753

4854
```shell
4955
kubectl get nodes k8s-linuxpool1-34450317-0 -o go-template --template='{{range .status.addresses}}{{printf "%s: %s\n" .type .address}}{{end}}'
5056
```
57+
5158
```
5259
Hostname: k8s-linuxpool1-34450317-0
5360
InternalIP: 10.0.0.5
@@ -56,40 +63,50 @@ InternalIP: 2001:db8:10::5
5663

5764
### Validate Pod addressing
5865

59-
Validate that a Pod has an IPv4 and IPv6 address assigned. Replace the Pod name with a valid Pod in your cluster. In this example the Pod name is `pod01`:
66+
Validate that a Pod has an IPv4 and IPv6 address assigned. Replace the Pod name with
67+
a valid Pod in your cluster. In this example the Pod name is `pod01`:
6068

6169
```shell
6270
kubectl get pods pod01 -o go-template --template='{{range .status.podIPs}}{{printf "%s\n" .ip}}{{end}}'
6371
```
72+
6473
```
6574
10.244.1.4
6675
2001:db8::4
6776
```
6877

69-
You can also validate Pod IPs using the Downward API via the `status.podIPs` fieldPath. The following snippet demonstrates how you can expose the Pod IPs via an environment variable called `MY_POD_IPS` within a container.
78+
You can also validate Pod IPs using the Downward API via the `status.podIPs` fieldPath.
79+
The following snippet demonstrates how you can expose the Pod IPs via an environment variable
80+
called `MY_POD_IPS` within a container.
7081

71-
```
82+
```yaml
7283
env:
7384
- name: MY_POD_IPS
7485
valueFrom:
7586
fieldRef:
7687
fieldPath: status.podIPs
7788
```
7889
79-
The following command prints the value of the `MY_POD_IPS` environment variable from within a container. The value is a comma separated list that corresponds to the Pod's IPv4 and IPv6 addresses.
90+
The following command prints the value of the `MY_POD_IPS` environment variable from
91+
within a container. The value is a comma separated list that corresponds to the
92+
Pod's IPv4 and IPv6 addresses.
8093

8194
```shell
8295
kubectl exec -it pod01 -- set | grep MY_POD_IPS
8396
```
97+
8498
```
8599
MY_POD_IPS=10.244.1.4,2001:db8::4
86100
```
87101
88-
The Pod's IP addresses will also be written to `/etc/hosts` within a container. The following command executes a cat on `/etc/hosts` on a dual stack Pod. From the output you can verify both the IPv4 and IPv6 IP address for the Pod.
102+
The Pod's IP addresses will also be written to `/etc/hosts` within a container.
103+
The following command executes a cat on `/etc/hosts` on a dual stack Pod.
104+
From the output you can verify both the IPv4 and IPv6 IP address for the Pod.
89105
90106
```shell
91107
kubectl exec -it pod01 -- cat /etc/hosts
92108
```
109+
93110
```
94111
# Kubernetes-managed hosts file.
95112
127.0.0.1 localhost
@@ -104,7 +121,9 @@ fe00::2 ip6-allrouters
104121

105122
## Validate Services
106123

107-
Create the following Service that does not explicitly define `.spec.ipFamilyPolicy`. Kubernetes will assign a cluster IP for the Service from the first configured `service-cluster-ip-range` and set the `.spec.ipFamilyPolicy` to `SingleStack`.
124+
Create the following Service that does not explicitly define `.spec.ipFamilyPolicy`.
125+
Kubernetes will assign a cluster IP for the Service from the first configured
126+
`service-cluster-ip-range` and set the `.spec.ipFamilyPolicy` to `SingleStack`.
108127

109128
{{% code_sample file="service/networking/dual-stack-default-svc.yaml" %}}
110129

@@ -114,7 +133,9 @@ Use `kubectl` to view the YAML for the Service.
114133
kubectl get svc my-service -o yaml
115134
```
116135

117-
The Service has `.spec.ipFamilyPolicy` set to `SingleStack` and `.spec.clusterIP` set to an IPv4 address from the first configured range set via `--service-cluster-ip-range` flag on kube-controller-manager.
136+
The Service has `.spec.ipFamilyPolicy` set to `SingleStack` and `.spec.clusterIP` set
137+
to an IPv4 address from the first configured range set via `--service-cluster-ip-range`
138+
flag on kube-controller-manager.
118139

119140
```yaml
120141
apiVersion: v1
@@ -141,7 +162,9 @@ status:
141162
loadBalancer: {}
142163
```
143164
144-
Create the following Service that explicitly defines `IPv6` as the first array element in `.spec.ipFamilies`. Kubernetes will assign a cluster IP for the Service from the IPv6 range configured `service-cluster-ip-range` and set the `.spec.ipFamilyPolicy` to `SingleStack`.
165+
Create the following Service that explicitly defines `IPv6` as the first array element in
166+
`.spec.ipFamilies`. Kubernetes will assign a cluster IP for the Service from the IPv6 range
167+
configured `service-cluster-ip-range` and set the `.spec.ipFamilyPolicy` to `SingleStack`.
145168

146169
{{% code_sample file="service/networking/dual-stack-ipfamilies-ipv6.yaml" %}}
147170

@@ -151,7 +174,8 @@ Use `kubectl` to view the YAML for the Service.
151174
kubectl get svc my-service -o yaml
152175
```
153176

154-
The Service has `.spec.ipFamilyPolicy` set to `SingleStack` and `.spec.clusterIP` set to an IPv6 address from the IPv6 range set via `--service-cluster-ip-range` flag on kube-controller-manager.
177+
The Service has `.spec.ipFamilyPolicy` set to `SingleStack` and `.spec.clusterIP` set to
178+
an IPv6 address from the IPv6 range set via `--service-cluster-ip-range` flag on kube-controller-manager.
155179

156180
```yaml
157181
apiVersion: v1
@@ -179,7 +203,10 @@ status:
179203
loadBalancer: {}
180204
```
181205

182-
Create the following Service that explicitly defines `PreferDualStack` in `.spec.ipFamilyPolicy`. Kubernetes will assign both IPv4 and IPv6 addresses (as this cluster has dual-stack enabled) and select the `.spec.ClusterIP` from the list of `.spec.ClusterIPs` based on the address family of the first element in the `.spec.ipFamilies` array.
206+
Create the following Service that explicitly defines `PreferDualStack` in `.spec.ipFamilyPolicy`.
207+
Kubernetes will assign both IPv4 and IPv6 addresses (as this cluster has dual-stack enabled) and
208+
select the `.spec.ClusterIP` from the list of `.spec.ClusterIPs` based on the address family of
209+
the first element in the `.spec.ipFamilies` array.
183210

184211
{{% code_sample file="service/networking/dual-stack-preferred-svc.yaml" %}}
185212

@@ -188,13 +215,16 @@ The `kubectl get svc` command will only show the primary IP in the `CLUSTER-IP`
188215

189216
```shell
190217
kubectl get svc -l app.kubernetes.io/name=MyApp
218+
```
191219

220+
```
192221
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
193222
my-service ClusterIP 10.0.216.242 <none> 80/TCP 5s
194223
```
195224
{{< /note >}}
196225
197-
Validate that the Service gets cluster IPs from the IPv4 and IPv6 address blocks using `kubectl describe`. You may then validate access to the service via the IPs and ports.
226+
Validate that the Service gets cluster IPs from the IPv4 and IPv6 address blocks using
227+
`kubectl describe`. You may then validate access to the service via the IPs and ports.
198228
199229
```shell
200230
kubectl describe svc -l app.kubernetes.io/name=MyApp
@@ -220,7 +250,9 @@ Events: <none>
220250

221251
### Create a dual-stack load balanced Service
222252

223-
If the cloud provider supports the provisioning of IPv6 enabled external load balancers, create the following Service with `PreferDualStack` in `.spec.ipFamilyPolicy`, `IPv6` as the first element of the `.spec.ipFamilies` array and the `type` field set to `LoadBalancer`.
253+
If the cloud provider supports the provisioning of IPv6 enabled external load balancers,
254+
create the following Service with `PreferDualStack` in `.spec.ipFamilyPolicy`, `IPv6` as
255+
the first element of the `.spec.ipFamilies` array and the `type` field set to `LoadBalancer`.
224256

225257
{{% code_sample file="service/networking/dual-stack-prefer-ipv6-lb-svc.yaml" %}}
226258

@@ -230,11 +262,10 @@ Check the Service:
230262
kubectl get svc -l app.kubernetes.io/name=MyApp
231263
```
232264

233-
Validate that the Service receives a `CLUSTER-IP` address from the IPv6 address block along with an `EXTERNAL-IP`. You may then validate access to the service via the IP and port.
265+
Validate that the Service receives a `CLUSTER-IP` address from the IPv6 address block
266+
along with an `EXTERNAL-IP`. You may then validate access to the service via the IP and port.
234267

235-
```shell
268+
```
236269
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
237270
my-service LoadBalancer 2001:db8:fd00::7ebc 2603:1030:805::5 80:30790/TCP 35s
238271
```
239-
240-

0 commit comments

Comments
 (0)