diff --git a/.vuepress/config.js b/.vuepress/config.js index 242742a..11ee561 100644 --- a/.vuepress/config.js +++ b/.vuepress/config.js @@ -327,6 +327,7 @@ module.exports = { 'k8s-intermediate/config/sec-ctx/con-cap', 'k8s-intermediate/config/sec-ctx/con-sel', 'k8s-intermediate/config/sec-ctx/volumes', + 'k8s-intermediate/config/sec-ctx/pod-kuboard', ] }, ] diff --git a/learning/k8s-intermediate/config/sec-ctx/pod-kuboard.assets/image-20191004221427371.png b/learning/k8s-intermediate/config/sec-ctx/pod-kuboard.assets/image-20191004221427371.png new file mode 100644 index 0000000..1dd5a88 Binary files /dev/null and b/learning/k8s-intermediate/config/sec-ctx/pod-kuboard.assets/image-20191004221427371.png differ diff --git a/learning/k8s-intermediate/config/sec-ctx/pod-kuboard.md b/learning/k8s-intermediate/config/sec-ctx/pod-kuboard.md new file mode 100644 index 0000000..eda22a6 --- /dev/null +++ b/learning/k8s-intermediate/config/sec-ctx/pod-kuboard.md @@ -0,0 +1,35 @@ +--- +vssueId: 114 +layout: LearningLayout +description: Kubernetes教程_在Kuboard中设置Pod的SecurityContext。通过 Kuboard,可以直接设定 Deployment、StatefulSet、DaemonSet 等中 Pod 模板的 securityContext 的内容。 +meta: + - name: keywords + content: Kubernetes教程,K8S教程,Security Context,SecurityContext +--- + +# Kuboard中Pod的Security Context + +通过 Kuboard,可以直接设定 Deployment、StatefulSet、DaemonSet 等中 Pod 模板的 securityContext 的内容。在 Kuboard 工作负载编辑器界面中点击 **容器组的更多设定** 按钮,可查看到 Pod 的 Security Context 设置界面,如下图所示: + +![Kubernetes教程_Kuboard中Pod的SecurityContext](./pod-kuboard.assets/image-20191004221427371.png) + + + +上图界面中,各个字段的含义逐个解释如下: + +| 字段名 | 字段类型 | 字段说明 | +| -------------- | -------- | ------------------------------------------------------------ | +| 非Root | boolean | 如果为 true,则 kubernetes 在运行容器之前将执行检查,以确保容器进程不是以 root 用户(UID为0)运行,否则将不能启动容器;如果此字段不设置或者为 false,则不执行此检查。该字段也可以在容器的 securityContext 中设定,如果 Pod 和容器的 securityContext 中都设定了这个字段,则对该容器来说以容器中的设置为准。 | +| 用户 | integer | 执行容器 entrypoint 进程的 UID。默认为镜像元数据中定义的用户(dockerfile 中通过 USER 指令指定)。该字段也可以在容器的 securityContext 中设定,如果 Pod 和容器的 securityContext 中都设定了这个字段,则对该容器来说以容器中的设置为准。 | +| 用户组 | integer | 执行容器 entrypoint 进程的 GID。默认为 docker 引擎的 GID。该字段也可以在容器的 securityContext 中设定,如果 Pod 和容器的 securityContext 中都设定了这个字段,则对该容器来说以容器中的设置为准。 | +| fsGroup | integer | 一个特殊的补充用户组,将被应用到 Pod 中所有容器。某些类型的数据卷允许 Kubelete 修改数据卷的 ownership:
1. 修改后的 GID 取值来自于 fsGroup
2. setgid 标记位被设为 1(此时,数据卷中新创建的文件 owner 为 fsGroup)
3. permission 标记将与 `rw-rw----` 执行或运算
如果该字段不设置,kubelete 将不会修改数据卷的 ownership 和 permission | +| 补充用户组 | integer | 该列表中的用户组将被作为容器的主 GID 的补充,添加到 Pod 中容器的 enrtypoint 进程。可以不设置。 | +| seLinuxOptions | Object | 此字段设定的 SELinux 上下文将被应用到 Pod 中所有容器。如果不指定,容器引擎将为每个容器分配一个随机的 SELinux 上下文。该字段也可以在容器的 securityContext 中设定,如果 Pod 和容器的 securityContext 中都设定了这个字段,则对该容器来说以容器中的设置为准。 | +| sysctls | Array | 该列表中的所有 sysctl 将被应用到 Pod 中的容器。如果定义了容器引擎不支持的 sysctl,Pod 启动将会失败 | + +关于 SecurityContex 在运行时怎么工作,请参考: +* [为Pod设置Security Context](./pod.html) +* [为容器设置Security Context](./con.html) +* [为容器设置Linux Capabilities](./con-cap.html) +* [为容器设置SELinux标签](./con-sel.html) +* [关于数据卷](./volumes.html) diff --git a/learning/k8s-intermediate/config/sec-ctx/pod.md b/learning/k8s-intermediate/config/sec-ctx/pod.md index 4d47d67..eb7a858 100644 --- a/learning/k8s-intermediate/config/sec-ctx/pod.md +++ b/learning/k8s-intermediate/config/sec-ctx/pod.md @@ -9,7 +9,7 @@ meta: # 为Pod设置Security Context -在 Pod 的定义中增加 `securityContext` 字段,即可为 Pod 指定 Security 相关的设定。 `securityContext` 字段是一个 [PodSecurityContext](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#podsecuritycontext-v1-core) 对象。通过该字段指定的内容将对该 Pod 中所有的容器生效。 +在 Pod 的定义中增加 `securityContext` 字段,即可为 Pod 指定 Security 相关的设定。 `securityContext` 字段是一个 [PodSecurityContext](./pod-kuboard.html) 对象。通过该字段指定的内容将对该 Pod 中所有的容器生效。 ## Pod示例