Skip to content

Commit e1b5264

Browse files
committed
[zh] Sync extend-service-ip-ranges.md
1 parent b3e0ed2 commit e1b5264

File tree

1 file changed

+158
-1
lines changed

1 file changed

+158
-1
lines changed

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

+158-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ This document shares how to extend the existing Service IP range assigned to a c
3030

3131
{{< version-check >}}
3232

33+
{{< note >}}
34+
<!--
35+
While you can use this feature with an earlier version, the feature is only GA and officially supported since v1.33.
36+
-->
37+
虽然你可以在更早的版本中使用此特性,但此特性只有从 v1.33 版本开始才进阶至 GA(正式发布)并获得官方支持。
38+
{{< /note >}}
39+
3340
<!-- steps -->
3441

35-
## API
42+
<!--
43+
## Extend Service IP Ranges
44+
-->
45+
## 扩展 Service IP 范围 {#extend-service-ip-ranges}
3646

3747
<!--
3848
Kubernetes clusters with kube-apiservers that have enabled the `MultiCIDRServiceAllocator`
@@ -260,3 +270,150 @@ kubectl get servicecidr newcidr1
260270
```
261271
Error from server (NotFound): servicecidrs.networking.k8s.io "newcidr1" not found
262272
```
273+
274+
<!--
275+
## Kubernetes Service CIDR Policies
276+
277+
Cluster administrators can implement policies to control the creation and
278+
modification of ServiceCIDR resources within the cluster. This allows for
279+
centralized management of the IP address ranges used for Services and helps
280+
prevent unintended or conflicting configurations. Kubernetes provides mechanisms
281+
like Validating Admission Policies to enforce these rules.
282+
-->
283+
## Kubernetes Service CIDR 策略 {#kubernetes-service-cidr-policies}
284+
285+
集群管理员可以实现策略来控制集群中 ServiceCIDR 资源的创建和修改。
286+
这允许集中管理 Service 所使用的 IP 地址范围,有助于防止意外或冲突的配置。
287+
Kubernetes 提供如验证准入策略(Validating Admission Policy)等机制来强制执行这些规则。
288+
289+
<!--
290+
### Preventing Unauthorized ServiceCIDR Creation/Update using Validating Admission Policy
291+
292+
There can be situations that the cluster administrators want to restrict the
293+
ranges that can be allowed or to completely deny any changes to the cluster
294+
Service IP ranges.
295+
-->
296+
### 使用验证准入策略阻止未授权的 ServiceCIDR 创建或更新
297+
298+
在某些情况下,集群管理员可能希望限制允许的 IP 范围,或完全禁止对集群 Service IP 范围的更改。
299+
300+
{{< note >}}
301+
<!--
302+
The default "kubernetes" ServiceCIDR is created by the kube-apiserver
303+
to provide consistency in the cluster and is required for the cluster to work,
304+
so it always must be allowed. You can ensure your `ValidatingAdmissionPolicy`
305+
doesn't restrict the default ServiceCIDR by adding the clause:
306+
-->
307+
默认的 "kubernetes" ServiceCIDR 是由 kube-apiserver 创建的,用于在集群中提供一致性,
308+
并且是集群正常运行所必需的,因此必须始终被允许。你可以通过在 `ValidatingAdmissionPolicy`
309+
中添加以下条件来确保不会限制默认的 ServiceCIDR:
310+
311+
```yaml
312+
matchConditions:
313+
- name: 'exclude-default-servicecidr'
314+
expression: "object.metadata.name != 'kubernetes'"
315+
```
316+
317+
<!--
318+
as in the examples below.
319+
-->
320+
如下例所示。
321+
322+
{{</ note >}}
323+
324+
<!--
325+
#### Restrict Service CIDR ranges to some specific ranges
326+
327+
The following is an example of a `ValidatingAdmissionPolicy` that only allows
328+
ServiceCIDRs to be created if they are subranges of the given `allowed` ranges.
329+
(So the example policy would allow a ServiceCIDR with `cidrs: ['10.96.1.0/24']`
330+
or `cidrs: ['2001:db8:0:0:ffff::/80', '10.96.0.0/20']` but would not allow a
331+
ServiceCIDR with `cidrs: ['172.20.0.0/16']`.) You can copy this policy and change
332+
the value of `allowed` to something appropriate for you cluster.
333+
-->
334+
#### 限制 Service CIDR 范围为某些特定范围
335+
336+
以下是一个 `ValidatingAdmissionPolicy` 的示例,它只允许在给定的 `allowed` 范围内的子范围创建 ServiceCIDR。
337+
(因此示例的策略允许 ServiceCIDR 使用 `cidrs: ['10.96.1.0/24']` 或
338+
`cidrs: ['2001:db8:0:0:ffff::/80', '10.96.0.0/20']`,但不允许 `cidrs: ['172.20.0.0/16']`。)
339+
你可以复制此策略,并将 `allowed` 的值更改为适合你集群的取值。
340+
341+
<!--
342+
# For all CIDRs (newCIDR) listed in the spec.cidrs of the submitted ServiceCIDR
343+
# object, check if there exists at least one CIDR (allowedCIDR) in the `allowed`
344+
# list of the VAP such that the allowedCIDR fully contains the newCIDR.
345+
-->
346+
```yaml
347+
apiVersion: admissionregistration.k8s.io/v1
348+
kind: ValidatingAdmissionPolicy
349+
metadata:
350+
name: "servicecidrs.default"
351+
spec:
352+
failurePolicy: Fail
353+
matchConstraints:
354+
resourceRules:
355+
- apiGroups: ["networking.k8s.io"]
356+
apiVersions: ["v1","v1beta1"]
357+
operations: ["CREATE", "UPDATE"]
358+
resources: ["servicecidrs"]
359+
matchConditions:
360+
- name: 'exclude-default-servicecidr'
361+
expression: "object.metadata.name != 'kubernetes'"
362+
variables:
363+
- name: allowed
364+
expression: "['10.96.0.0/16','2001:db8::/64']"
365+
validations:
366+
- expression: "object.spec.cidrs.all(newCIDR, variables.allowed.exists(allowedCIDR, cidr(allowedCIDR).containsCIDR(newCIDR)))"
367+
# 对提交的 ServiceCIDR 对象的 spec.cidrs 中列出的所有 CIDR(newCIDR),
368+
# 检查 VAP 的 `allowed` 列表中是否至少存在一个 CIDR(allowedCIDR),
369+
# 使 allowedCIDR 完全包含 newCIDR。
370+
---
371+
apiVersion: admissionregistration.k8s.io/v1
372+
kind: ValidatingAdmissionPolicyBinding
373+
metadata:
374+
name: "servicecidrs-binding"
375+
spec:
376+
policyName: "servicecidrs.default"
377+
validationActions: [Deny,Audit]
378+
```
379+
380+
<!--
381+
Consult the [CEL documentation](https://kubernetes.io/docs/reference/using-api/cel/)
382+
to learn more about CEL if you want to write your own validation `expression`.
383+
384+
#### Restrict any usage of the ServiceCIDR API
385+
386+
The following example demonstrates how to use a `ValidatingAdmissionPolicy` and
387+
its binding to restrict the creation of any new Service CIDR ranges, excluding the default "kubernetes" ServiceCIDR:
388+
-->
389+
如果你想要编写自己的验证 `expression`,参阅 [CEL 文档](/zh-cn/docs/reference/using-api/cel/)以了解更多信息。
390+
391+
#### 限制任何对 ServiceCIDR API 的使用
392+
393+
以下示例展示了如何使用 `ValidatingAdmissionPolicy` 及其绑定,
394+
来限制创建任何新的 Service CIDR 范围,但不包括默认的 "kubernetes" ServiceCIDR:
395+
396+
```yaml
397+
apiVersion: admissionregistration.k8s.io/v1
398+
kind: ValidatingAdmissionPolicy
399+
metadata:
400+
name: "servicecidrs.deny"
401+
spec:
402+
failurePolicy: Fail
403+
matchConstraints:
404+
resourceRules:
405+
- apiGroups: ["networking.k8s.io"]
406+
apiVersions: ["v1","v1beta1"]
407+
operations: ["CREATE", "UPDATE"]
408+
resources: ["servicecidrs"]
409+
validations:
410+
- expression: "object.metadata.name == 'kubernetes'"
411+
---
412+
apiVersion: admissionregistration.k8s.io/v1
413+
kind: ValidatingAdmissionPolicyBinding
414+
metadata:
415+
name: "servicecidrs-deny-binding"
416+
spec:
417+
policyName: "servicecidrs.deny"
418+
validationActions: [Deny,Audit]
419+
```

0 commit comments

Comments
 (0)