题目要求
在 test 命名空间,有一个名为 secnginx 的 pod,修改此 pod,为容器添加CAP_NET_ADMIN 和 CAP_SYS_TIME 权能
参考
https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/security-context/#set-capabilities-for-a-container
1 2 3 4 5 6 7 8 9 10 11 12
| apiVersion: v1 kind: Pod metadata: name: security-context-demo-4 spec: containers: - name: sec-ctx-4 image: gcr.io/google-samples/node-hello:1.0 securityContext: capabilities: add: ["NET_ADMIN", "SYS_TIME"]
|
解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| kubectl create ns test
kubectl run secnginx --image=nginx --dry-run=client -o yaml > 26-ecurity-context.yaml
vim 26-ecurity-context.yaml apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: secnginx name: secnginx spec: containers: - image: nginx name: secnginx securityContext: capabilities: add: ["NET_ADMIN", "SYS_TIME"] dnsPolicy: ClusterFirst restartPolicy: Always status: {}
kubectl -n test apply -f 26-ecurity-context.yaml
|