Kubernetes 安全上下文

Kubernetes securityContext

我似乎无法理解为什么如果我删除 spec.containers.command,下面提到的 pod 清单将不起作用,如果我删除命令,pod 会失败。

这个例子是我从官方拿来的documentation

apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo
spec:
  securityContext:
    runAsUser: 1000
    runAsGroup: 3000
    fsGroup: 2000
  volumes:
  - name: sec-ctx-vol
    emptyDir: {}
  containers:
  - name: sec-ctx-demo
    image: busybox
    command: [ "sh", "-c", "sleep 1h" ]
    volumeMounts:
    - name: sec-ctx-vol
      mountPath: /data/demo
    securityContext:
      allowPrivilegeEscalation: false

因为 busybox 图像本身不会 运行 启动任何进程。容器旨在 运行 单个应用程序并在应用程序退出时关闭。如果图像没有 运行 任何内容,它将立即退出。在 Kubernetes 中,spec.containers.command 会覆盖默认的容器命令。您可以尝试更改清单图像,即 image: nginx,删除 spec.containers.command,它将 运行,因为该图像是默认的 Nginx 服务器。