@@ -402,12 +402,19 @@ controller selects policies according to the following criteria:
402
402
PodSecurityPolicies doesn't matter.
403
403
2. If the pod must be defaulted or mutated, the first PodSecurityPolicy
404
404
(ordered by name) to allow the pod is selected.
405
+
406
+ When a Pod is validated against a PodSecurityPolicy, [a `kubernetes.io/psp` annotation](/docs/reference/labels-annotations-taints/#kubernetes-io-psp)
407
+ is added to the Pod, with the name of the PodSecurityPolicy as the annotation value.
405
408
-->
406
409
1. 优先考虑允许 Pod 保持原样,不会更改 Pod 字段默认值或其他配置的 PodSecurityPolicy。
407
410
这类非更改性质的 PodSecurityPolicy 对象之间的顺序无关紧要。
408
411
2. 如果必须要为 Pod 设置默认值或者其他配置,(按名称顺序)选择第一个允许
409
412
Pod 操作的 PodSecurityPolicy 对象。
410
413
414
+ 当根据 PodSecurityPolicy 对一个 Pod 进行验证时,会为 Pod 添加
415
+ [一个 `kubernetes.io/psp` 注释](/zh-cn/docs/reference/labels-annotations-taints/#kubernetes-io-psp)会被添加到 Pod 中,
416
+ 注解的值为 PodSecurityPolicy 的名称。
417
+
411
418
{{< note >}}
412
419
<!--
413
420
During update operations (during which mutations to pod specs are disallowed)
@@ -457,15 +464,15 @@ alias kubectl-user='kubectl --as=system:serviceaccount:psp-example:fake-user -n
457
464
<!--
458
465
# ## Create a policy and a pod
459
466
460
- Define the example PodSecurityPolicy object in a file. This is a policy that
461
- prevents the creation of privileged pods.
467
+ This is a policy that prevents the creation of privileged pods.
468
+
462
469
The name of a PodSecurityPolicy object must be a valid
463
470
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
464
471
-->
465
472
# ## 创建一个策略和一个 Pod {#create-a-policy-and-a-pod}
466
473
467
- 在一个文件中定义一个示例的 PodSecurityPolicy 对象 。
468
- 这里的策略只是用来禁止创建有特权要求的 Pods。
474
+ 下面是一个防止创建特权 Pod 的策略 。
475
+
469
476
PodSecurityPolicy 对象的名称必须是合法的
470
477
[DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)。
471
478
@@ -477,7 +484,7 @@ And create it with kubectl:
477
484
使用 kubectl 执行创建操作:
478
485
479
486
` ` ` shell
480
- kubectl-admin create -f example-psp.yaml
487
+ kubectl-admin create -f https://k8s.io/examples/policy/ example-psp.yaml
481
488
` ` `
482
489
483
490
<!--
@@ -517,6 +524,11 @@ pod's service account nor `fake-user` have permission to use the new policy:
517
524
kubectl-user auth can-i use podsecuritypolicy/example
518
525
```
519
526
527
+ <!--
528
+ The output is similar to this:
529
+ -->
530
+ 输出类似于:
531
+
520
532
```
521
533
no
522
534
```
@@ -597,11 +609,29 @@ pod "pause" created
597
609
```
598
610
599
611
<!--
600
- It works as expected! But any attempts to create a privileged pod should still
601
- be denied :
612
+ It works as expected! You can verify that the pod was validated against the
613
+ newly created PodSecurityPolicy :
602
614
-->
603
615
此次尝试不出所料地成功了!
604
- 不过任何创建特权 Pod 的尝试还是会被拒绝:
616
+ 你可以验证 Pod 是根据新创建的 PodSecurityPolicy 验证的。
617
+
618
+ ``` shell
619
+ kubectl-user get pod pause -o yaml | grep kubernetes.io/psp
620
+ ```
621
+
622
+ <!--
623
+ The output is similar to this:
624
+ -->
625
+ 输出类似于:
626
+
627
+ ```
628
+ kubernetes.io/psp: example
629
+ ```
630
+ <!--
631
+ But any attempts to create a privileged pod should still
632
+ be denied:
633
+ -->
634
+ 但任何试图创建特权 Pod 的请求仍然会被拒绝。
605
635
606
636
``` shell
607
637
kubectl-user create -f- << EOF
0 commit comments