@@ -3,7 +3,7 @@ title: 在集群级别应用 Pod 安全标准
33content_type : tutorial
44weight : 10
55---
6- <!--
6+ <!--
77title: Apply Pod Security Standards at the Cluster Level
88content_type: tutorial
99weight: 10
@@ -16,7 +16,7 @@ This tutorial applies only for new clusters.
1616本教程仅适用于新集群。
1717{{% /alert %}}
1818
19- <!--
19+ <!--
2020Pod Security admission (PSA) is enabled by default in v1.23 and later, as it has
2121[graduated to beta](/blog/2021/12/09/pod-security-admission-beta/).
2222Pod Security
@@ -46,7 +46,7 @@ Pod 安全准入是在创建 Pod 时应用
4646请查阅该版本的文档。
4747
4848## {{% heading "prerequisites" %}}
49- <!--
49+ <!--
5050Install the following on your workstation:
5151
5252- [KinD](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
@@ -65,7 +65,7 @@ lets you apply built-in [Pod Security Standards](/docs/concepts/security/pod-sec
6565with the following modes: `enforce`, `audit`, and `warn`.
6666
6767To gather information that helps you to choose the Pod Security Standards
68- that are most appropriate for your configuration, do the following:
68+ that are most appropriate for your configuration, do the following:
6969-->
7070## 正确选择要应用的 Pod 安全标准 {#choose-the-right-pod-security-standard-to-apply}
7171
@@ -76,7 +76,7 @@ that are most appropriate for your configuration, do the following:
7676
7777要收集信息以便选择最适合你的配置的 Pod 安全标准,请执行以下操作:
7878
79- <!--
79+ <!--
80801. Create a cluster with no Pod Security Standards applied:
8181-->
82821 . 创建一个没有应用 Pod 安全标准的集群:
@@ -89,20 +89,20 @@ that are most appropriate for your configuration, do the following:
8989 ```
9090 Creating cluster "psa-wo-cluster-pss" ...
9191 ✓ Ensuring node image (kindest/node:v1.24.0) 🖼
92- ✓ Preparing nodes 📦
92+ ✓ Preparing nodes 📦
9393 ✓ Writing configuration 📜
9494 ✓ Starting control-plane 🕹️
9595 ✓ Installing CNI 🔌
9696 ✓ Installing StorageClass 💾
9797 Set kubectl context to "kind-psa-wo-cluster-pss"
9898 You can now use your cluster with:
99-
99+
100100 kubectl cluster-info --context kind-psa-wo-cluster-pss
101-
101+
102102 Thanks for using kind! 😊
103103 ```
104104
105- <!--
105+ <!--
1061061. Set the kubectl context to the new cluster:
107107-->
1081082 . 将 kubectl 上下文设置为新集群:
@@ -116,11 +116,11 @@ that are most appropriate for your configuration, do the following:
116116 Kubernetes control plane is running at https://127.0.0.1:61350
117117
118118 CoreDNS is running at https://127.0.0.1:61350/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
119-
119+
120120 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
121121 ```
122122
123- <!--
123+ <!--
1241241. Get a list of namespaces in the cluster:
125125-->
1261263 . 获取集群中的名字空间列表:
@@ -130,7 +130,7 @@ that are most appropriate for your configuration, do the following:
130130 ```
131131 <!-- The output is similar to this: -->
132132 输出类似于:
133- ```
133+ ```
134134 NAME STATUS AGE
135135 default Active 9m30s
136136 kube-node-lease Active 9m32s
@@ -139,34 +139,34 @@ that are most appropriate for your configuration, do the following:
139139 local-path-storage Active 9m26s
140140 ```
141141
142- <!--
142+ <!--
1431431. Use `--dry-run=server` to understand what happens when different Pod Security Standards
144144 are applied:
145145-->
1461464 . 使用 ` --dry-run=server ` 来了解应用不同的 Pod 安全标准时会发生什么:
147147
148148 1 . Privileged
149149 ``` shell
150- kubectl label --dry-run=server --overwrite ns --all \
150+ kubectl label --dry-run=server --overwrite ns --all \
151151 pod-security.kubernetes.io/enforce=privileged
152152 ```
153153 < ! -- The output is similar to this: -->
154154 输出类似于:
155- ```
156- namespace/default labeled
157- namespace/kube-node-lease labeled
158- namespace/kube-public labeled
159- namespace/kube-system labeled
160- namespace/local-path-storage labeled
161- ```
155+ ```
156+ namespace/default labeled
157+ namespace/kube-node-lease labeled
158+ namespace/kube-public labeled
159+ namespace/kube-system labeled
160+ namespace/local-path-storage labeled
161+ ```
162162 2. Baseline
163163 ` ` ` shell
164164 kubectl label --dry-run=server --overwrite ns --all \
165165 pod-security.kubernetes.io/enforce=baseline
166166 ` ` `
167167 < ! -- The output is similar to this: -->
168168 输出类似于:
169- ```
169+ ```
170170 namespace/default labeled
171171 namespace/kube-node-lease labeled
172172 namespace/kube-public labeled
@@ -185,7 +185,7 @@ that are most appropriate for your configuration, do the following:
185185 ` ` `
186186 < ! -- The output is similar to this: -->
187187 输出类似于:
188- ```
188+ ```
189189 namespace/default labeled
190190 namespace/kube-node-lease labeled
191191 namespace/kube-public labeled
@@ -200,15 +200,16 @@ that are most appropriate for your configuration, do the following:
200200 namespace/local-path-storage labeled
201201 ```
202202
203- < ! --
203+ < ! --
204204From the previous output, you' ll notice that applying the `privileged` Pod Security Standard shows no warnings
205205for any namespaces. However, `baseline` and `restricted` standards both have
206206warnings, specifically in the `kube-system` namespace.
207207-->
208+
208209从前面的输出中,你会注意到应用 `privileged` Pod 安全标准不会显示任何名字空间的警告。
209210然而,`baseline` 和 `restricted` 标准都有警告,特别是在 `kube-system` 名字空间中。
210211
211- <!--
212+ <!--
212213## Set modes, versions and standards
213214
214215In this section, you apply the following Pod Security Standards to the `latest` version:
@@ -223,7 +224,7 @@ In this section, you apply the following Pod Security Standards to the `latest`
223224* 在 `enforce` 模式下的 `baseline` 标准。
224225* `warn` 和 `audit` 模式下的 `restricted` 标准。
225226
226- <!--
227+ <!--
227228The `baseline` Pod Security Standard provides a convenient
228229middle ground that allows keeping the exemption list short and prevents known
229230privilege escalations.
@@ -240,7 +241,7 @@ following:
240241
241242在你自己的环境中实施 Pod 安全准入时,请考虑以下事项:
242243
243- < ! --
244+ < ! --
2442451. Based on the risk posture applied to a cluster, a stricter Pod Security
245246 Standard like ` restricted` might be a better choice.
2462471. Exempting the ` kube-system` namespace allows pods to run as
@@ -260,7 +261,7 @@ following:
260261
261262 ```
262263 mkdir -p /tmp/pss
263- cat <<EOF > /tmp/pss/cluster-level-pss.yaml
264+ cat <<EOF > /tmp/pss/cluster-level-pss.yaml
264265 apiVersion: apiserver.config.k8s.io/v1
265266 kind: AdmissionConfiguration
266267 plugins:
@@ -293,13 +294,13 @@ following:
293294 对于 v1.22,使用 [v1alpha1](https://v1-22.docs.kubernetes.io/docs/tasks/configure-pod-container/enforce-standards-admission-controller/)。
294295 {{< /note >}}
295296
296- <!--
297+ <!--
2972981. Configure the API server to consume this file during cluster creation:
298299-->
2993004. 在创建集群时配置 API 服务器使用此文件:
300301
301302 ```
302- cat <<EOF > /tmp/pss/cluster-config.yaml
303+ cat <<EOF > /tmp/pss/cluster-config.yaml
303304 kind: Cluster
304305 apiVersion: kind.x-k8s.io/v1alpha4
305306 nodes:
@@ -333,7 +334,7 @@ following:
333334 ```
334335
335336 {{<note>}}
336- <!--
337+ <!--
337338 If you use Docker Desktop with KinD on macOS, you can
338339 add `/tmp` as a Shared Directory under the menu item
339340 **Preferences > Resources > File Sharing**.
@@ -343,7 +344,7 @@ following:
343344 下添加 `/tmp` 作为共享目录。
344345 {{</note>}}
345346
346- <!--
347+ <!--
3473481. Create a cluster that uses Pod Security Admission to apply
348349 these Pod Security Standards:
349350-->
@@ -356,22 +357,22 @@ following:
356357 输出类似于:
357358 ```
358359 Creating cluster "psa-with-cluster-pss" ...
359- ✓ Ensuring node image (kindest/node:v1.24.0) 🖼
360- ✓ Preparing nodes 📦
361- ✓ Writing configuration 📜
362- ✓ Starting control-plane 🕹️
363- ✓ Installing CNI 🔌
364- ✓ Installing StorageClass 💾
360+ ✓ Ensuring node image (kindest/node:v1.24.0) 🖼
361+ ✓ Preparing nodes 📦
362+ ✓ Writing configuration 📜
363+ ✓ Starting control-plane 🕹️
364+ ✓ Installing CNI 🔌
365+ ✓ Installing StorageClass 💾
365366 Set kubectl context to "kind-psa-with-cluster-pss"
366367 You can now use your cluster with:
367-
368+
368369 kubectl cluster-info --context kind-psa-with-cluster-pss
369-
370+
370371 Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂
371372 ```
372373
373- <!--
374- 1. Point kubectl to the cluster
374+ <!--
375+ 1. Point kubectl to the cluster:
375376-->
3763776 . 将 kubectl 指向集群
377378
@@ -383,11 +384,10 @@ following:
383384 ```
384385 Kubernetes control plane is running at https://127.0.0.1:63855
385386 CoreDNS is running at https://127.0.0.1:63855/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
386-
387+
387388 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
388389 ```
389-
390- <!--
390+ <!--
3913911. Create the following Pod specification for a minimal configuration in the default namespace:
392392-->
3933937 . 创建以下 Pod 规约作为在 default 名字空间中的一个最小配置:
@@ -406,8 +406,7 @@ following:
406406 - containerPort: 80
407407 EOF
408408 ```
409-
410- <!--
409+ <!--
4114101. Create the Pod in the cluster:
412411-->
4134128 . 在集群中创建 Pod:
@@ -422,7 +421,7 @@ following:
422421 pod/nginx created
423422 ```
424423
425- <!--
424+ <!--
426425## Clean up
427426
428427Now delete the clusters which you created above by running the following command:
@@ -440,7 +439,7 @@ kind delete cluster --name psa-wo-cluster-pss
440439
441440## {{% heading "whatsnext" %}}
442441
443- <!--
442+ <!--
444443- Run a
445444 [shell script](/examples/security/kind-with-cluster-level-baseline-pod-security.sh)
446445 to perform all the preceding steps at once:
@@ -464,4 +463,4 @@ kind delete cluster --name psa-wo-cluster-pss
464463 6 . 应用这个文件,在新集群中创建一个 Pod
465464- [ Pod 安全准入] ( /zh-cn/docs/concepts/security/pod-security-admission/ )
466465- [ Pod 安全标准] ( /zh-cn/docs/concepts/security/pod-security-standards/ )
467- - [ 在名字空间级别应用 Pod 安全标准] ( /zh-cn/docs/tutorials/security/ns-level-pss/ )
466+ - [ 在名字空间级别应用 Pod 安全标准] ( /zh-cn/docs/tutorials/security/ns-level-pss/ )
0 commit comments