@@ -438,10 +438,7 @@ IP addresses that are no longer used by any Services.
438
438
439
439
{{< feature-state feature_gate_name="MultiCIDRServiceAllocator" >}}
440
440
441
- If you enable the ` MultiCIDRServiceAllocator `
442
- [ feature gate] ( /docs/reference/command-line-tools-reference/feature-gates/ ) and the
443
- [ ` networking.k8s.io/v1alpha1 ` API group] ( /docs/tasks/administer-cluster/enable-disable-api/ ) ,
444
- the control plane replaces the existing etcd allocator with a revised implementation
441
+ The control plane replaces the existing etcd allocator with a revised implementation
445
442
that uses IPAddress and ServiceCIDR objects instead of an internal global allocation map.
446
443
Each cluster IP address associated to a Service then references an IPAddress object.
447
444
@@ -495,7 +492,7 @@ Users can create or delete new ServiceCIDR objects to manage the available IP ra
495
492
496
493
``` shell
497
494
cat << 'EOF ' | kubectl apply -f -
498
- apiVersion: networking.k8s.io/v1beta1
495
+ apiVersion: networking.k8s.io/v1
499
496
kind: ServiceCIDR
500
497
metadata:
501
498
name: newservicecidr
@@ -517,6 +514,46 @@ kubernetes 10.96.0.0/28 17m
517
514
newservicecidr 10.96.0.0/24 7m
518
515
```
519
516
517
+ Distributions or administrators of Kubernetes clusters may want to control that
518
+ new Service CIDRs added to the cluster does not overlap with other networks on
519
+ the cluster, that only belong to a specific range of IPs or just simple retain
520
+ the existing behavior of only having one ServiceCIDR per cluster. An example of
521
+ a Validation Admission Policy to achieve this is:
522
+
523
+ ``` yaml
524
+ ---
525
+ apiVersion : admissionregistration.k8s.io/v1
526
+ kind : ValidatingAdmissionPolicy
527
+ metadata :
528
+ name : " servicecidrs-default"
529
+ spec :
530
+ failurePolicy : Fail
531
+ matchConstraints :
532
+ resourceRules :
533
+ - apiGroups : ["networking.k8s.io"]
534
+ apiVersions : ["v1","v1beta1"]
535
+ operations : ["CREATE", "UPDATE"]
536
+ resources : ["servicecidrs"]
537
+ matchConditions :
538
+ - name : ' exclude-default-servicecidr'
539
+ expression : " object.metadata.name != 'kubernetes'"
540
+ variables :
541
+ - name : allowed
542
+ expression : " ['10.96.0.0/16','2001:db8::/64']"
543
+ validations :
544
+ - expression : " object.spec.cidrs.all(i , variables.allowed.exists(j , cidr(j).containsCIDR(i)))"
545
+ ---
546
+ apiVersion : admissionregistration.k8s.io/v1
547
+ kind : ValidatingAdmissionPolicyBinding
548
+ metadata :
549
+ name : " servicecidrs-binding"
550
+ spec :
551
+ policyName : " servicecidrs-default"
552
+ validationActions : [Deny,Audit]
553
+ ---
554
+ ```
555
+
556
+
520
557
### IP address ranges for Service virtual IP addresses {#service-ip-static-sub-range}
521
558
522
559
{{< feature-state for_k8s_version="v1.26" state="stable" >}}
0 commit comments