@@ -3,7 +3,7 @@ title: 在集群级别应用 Pod 安全标准
3
3
content_type : tutorial
4
4
weight : 10
5
5
---
6
- <!--
6
+ <!--
7
7
title: Apply Pod Security Standards at the Cluster Level
8
8
content_type: tutorial
9
9
weight: 10
@@ -16,7 +16,7 @@ This tutorial applies only for new clusters.
16
16
本教程仅适用于新集群。
17
17
{{% /alert %}}
18
18
19
- <!--
19
+ <!--
20
20
Pod Security admission (PSA) is enabled by default in v1.23 and later, as it has
21
21
[graduated to beta](/blog/2021/12/09/pod-security-admission-beta/).
22
22
Pod Security
@@ -46,7 +46,7 @@ Pod 安全准入是在创建 Pod 时应用
46
46
请查阅该版本的文档。
47
47
48
48
## {{% heading "prerequisites" %}}
49
- <!--
49
+ <!--
50
50
Install the following on your workstation:
51
51
52
52
- [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
65
65
with the following modes: `enforce`, `audit`, and `warn`.
66
66
67
67
To 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:
69
69
-->
70
70
## 正确选择要应用的 Pod 安全标准 {#choose-the-right-pod-security-standard-to-apply}
71
71
@@ -76,7 +76,7 @@ that are most appropriate for your configuration, do the following:
76
76
77
77
要收集信息以便选择最适合你的配置的 Pod 安全标准,请执行以下操作:
78
78
79
- <!--
79
+ <!--
80
80
1. Create a cluster with no Pod Security Standards applied:
81
81
-->
82
82
1 . 创建一个没有应用 Pod 安全标准的集群:
@@ -89,20 +89,20 @@ that are most appropriate for your configuration, do the following:
89
89
```
90
90
Creating cluster "psa-wo-cluster-pss" ...
91
91
✓ Ensuring node image (kindest/node:v1.24.0) 🖼
92
- ✓ Preparing nodes 📦
92
+ ✓ Preparing nodes 📦
93
93
✓ Writing configuration 📜
94
94
✓ Starting control-plane 🕹️
95
95
✓ Installing CNI 🔌
96
96
✓ Installing StorageClass 💾
97
97
Set kubectl context to "kind-psa-wo-cluster-pss"
98
98
You can now use your cluster with:
99
-
99
+
100
100
kubectl cluster-info --context kind-psa-wo-cluster-pss
101
-
101
+
102
102
Thanks for using kind! 😊
103
103
```
104
104
105
- <!--
105
+ <!--
106
106
1. Set the kubectl context to the new cluster:
107
107
-->
108
108
2 . 将 kubectl 上下文设置为新集群:
@@ -116,11 +116,11 @@ that are most appropriate for your configuration, do the following:
116
116
Kubernetes control plane is running at https://127.0.0.1:61350
117
117
118
118
CoreDNS is running at https://127.0.0.1:61350/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
119
-
119
+
120
120
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
121
121
```
122
122
123
- <!--
123
+ <!--
124
124
1. Get a list of namespaces in the cluster:
125
125
-->
126
126
3 . 获取集群中的名字空间列表:
@@ -130,7 +130,7 @@ that are most appropriate for your configuration, do the following:
130
130
```
131
131
<!-- The output is similar to this: -->
132
132
输出类似于:
133
- ```
133
+ ```
134
134
NAME STATUS AGE
135
135
default Active 9m30s
136
136
kube-node-lease Active 9m32s
@@ -139,34 +139,34 @@ that are most appropriate for your configuration, do the following:
139
139
local-path-storage Active 9m26s
140
140
```
141
141
142
- <!--
142
+ <!--
143
143
1. Use `--dry-run=server` to understand what happens when different Pod Security Standards
144
144
are applied:
145
145
-->
146
146
4 . 使用 ` --dry-run=server ` 来了解应用不同的 Pod 安全标准时会发生什么:
147
147
148
148
1 . Privileged
149
149
``` shell
150
- kubectl label --dry-run=server --overwrite ns --all \
150
+ kubectl label --dry-run=server --overwrite ns --all \
151
151
pod-security.kubernetes.io/enforce=privileged
152
152
```
153
153
< ! -- The output is similar to this: -->
154
154
输出类似于:
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
+ ```
162
162
2. Baseline
163
163
` ` ` shell
164
164
kubectl label --dry-run=server --overwrite ns --all \
165
165
pod-security.kubernetes.io/enforce=baseline
166
166
` ` `
167
167
< ! -- The output is similar to this: -->
168
168
输出类似于:
169
- ```
169
+ ```
170
170
namespace/default labeled
171
171
namespace/kube-node-lease labeled
172
172
namespace/kube-public labeled
@@ -185,7 +185,7 @@ that are most appropriate for your configuration, do the following:
185
185
` ` `
186
186
< ! -- The output is similar to this: -->
187
187
输出类似于:
188
- ```
188
+ ```
189
189
namespace/default labeled
190
190
namespace/kube-node-lease labeled
191
191
namespace/kube-public labeled
@@ -200,15 +200,16 @@ that are most appropriate for your configuration, do the following:
200
200
namespace/local-path-storage labeled
201
201
```
202
202
203
- < ! --
203
+ < ! --
204
204
From the previous output, you' ll notice that applying the `privileged` Pod Security Standard shows no warnings
205
205
for any namespaces. However, `baseline` and `restricted` standards both have
206
206
warnings, specifically in the `kube-system` namespace.
207
207
-->
208
+
208
209
从前面的输出中,你会注意到应用 `privileged` Pod 安全标准不会显示任何名字空间的警告。
209
210
然而,`baseline` 和 `restricted` 标准都有警告,特别是在 `kube-system` 名字空间中。
210
211
211
- <!--
212
+ <!--
212
213
## Set modes, versions and standards
213
214
214
215
In 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`
223
224
* 在 `enforce` 模式下的 `baseline` 标准。
224
225
* `warn` 和 `audit` 模式下的 `restricted` 标准。
225
226
226
- <!--
227
+ <!--
227
228
The `baseline` Pod Security Standard provides a convenient
228
229
middle ground that allows keeping the exemption list short and prevents known
229
230
privilege escalations.
@@ -240,7 +241,7 @@ following:
240
241
241
242
在你自己的环境中实施 Pod 安全准入时,请考虑以下事项:
242
243
243
- < ! --
244
+ < ! --
244
245
1. Based on the risk posture applied to a cluster, a stricter Pod Security
245
246
Standard like ` restricted` might be a better choice.
246
247
1. Exempting the ` kube-system` namespace allows pods to run as
@@ -260,7 +261,7 @@ following:
260
261
261
262
```
262
263
mkdir -p /tmp/pss
263
- cat <<EOF > /tmp/pss/cluster-level-pss.yaml
264
+ cat <<EOF > /tmp/pss/cluster-level-pss.yaml
264
265
apiVersion: apiserver.config.k8s.io/v1
265
266
kind: AdmissionConfiguration
266
267
plugins:
@@ -293,13 +294,13 @@ following:
293
294
对于 v1.22,使用 [v1alpha1](https://v1-22.docs.kubernetes.io/docs/tasks/configure-pod-container/enforce-standards-admission-controller/)。
294
295
{{< /note >}}
295
296
296
- <!--
297
+ <!--
297
298
1. Configure the API server to consume this file during cluster creation:
298
299
-->
299
300
4. 在创建集群时配置 API 服务器使用此文件:
300
301
301
302
```
302
- cat <<EOF > /tmp/pss/cluster-config.yaml
303
+ cat <<EOF > /tmp/pss/cluster-config.yaml
303
304
kind: Cluster
304
305
apiVersion: kind.x-k8s.io/v1alpha4
305
306
nodes:
@@ -333,7 +334,7 @@ following:
333
334
```
334
335
335
336
{{<note>}}
336
- <!--
337
+ <!--
337
338
If you use Docker Desktop with KinD on macOS, you can
338
339
add `/tmp` as a Shared Directory under the menu item
339
340
**Preferences > Resources > File Sharing**.
@@ -343,7 +344,7 @@ following:
343
344
下添加 `/tmp` 作为共享目录。
344
345
{{</note>}}
345
346
346
- <!--
347
+ <!--
347
348
1. Create a cluster that uses Pod Security Admission to apply
348
349
these Pod Security Standards:
349
350
-->
@@ -356,22 +357,22 @@ following:
356
357
输出类似于:
357
358
```
358
359
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 💾
365
366
Set kubectl context to "kind-psa-with-cluster-pss"
366
367
You can now use your cluster with:
367
-
368
+
368
369
kubectl cluster-info --context kind-psa-with-cluster-pss
369
-
370
+
370
371
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂
371
372
```
372
373
373
- <!--
374
- 1. Point kubectl to the cluster
374
+ <!--
375
+ 1. Point kubectl to the cluster:
375
376
-->
376
377
6 . 将 kubectl 指向集群
377
378
@@ -383,11 +384,10 @@ following:
383
384
```
384
385
Kubernetes control plane is running at https://127.0.0.1:63855
385
386
CoreDNS is running at https://127.0.0.1:63855/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
386
-
387
+
387
388
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
388
389
```
389
-
390
- <!--
390
+ <!--
391
391
1. Create the following Pod specification for a minimal configuration in the default namespace:
392
392
-->
393
393
7 . 创建以下 Pod 规约作为在 default 名字空间中的一个最小配置:
@@ -406,8 +406,7 @@ following:
406
406
- containerPort: 80
407
407
EOF
408
408
```
409
-
410
- <!--
409
+ <!--
411
410
1. Create the Pod in the cluster:
412
411
-->
413
412
8 . 在集群中创建 Pod:
@@ -422,7 +421,7 @@ following:
422
421
pod/nginx created
423
422
```
424
423
425
- <!--
424
+ <!--
426
425
## Clean up
427
426
428
427
Now delete the clusters which you created above by running the following command:
@@ -440,7 +439,7 @@ kind delete cluster --name psa-wo-cluster-pss
440
439
441
440
## {{% heading "whatsnext" %}}
442
441
443
- <!--
442
+ <!--
444
443
- Run a
445
444
[shell script](/examples/security/kind-with-cluster-level-baseline-pod-security.sh)
446
445
to perform all the preceding steps at once:
@@ -464,4 +463,4 @@ kind delete cluster --name psa-wo-cluster-pss
464
463
6 . 应用这个文件,在新集群中创建一个 Pod
465
464
- [ Pod 安全准入] ( /zh-cn/docs/concepts/security/pod-security-admission/ )
466
465
- [ 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