【问题标题】:Kubernetes securityContextKubernetes 安全上下文
【发布时间】:2021-12-14 13:57:10
【问题描述】:

如果我删除 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

【问题讨论】:

    标签: kubernetes kubernetes-security


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 2019-01-14
      • 1970-01-01
      • 2018-07-10
      • 2011-08-18
      • 1970-01-01
      • 2015-12-23
      • 2015-09-13
      • 2017-05-04
      相关资源
      最近更新 更多