k8s——pod的资源配置文件详解(manifest)
pod的资源配置文件(manifest)
详细介绍pod的资源配置文件(mannifest)的各个字段的含义
元数据
字段 | 是否必须 | 类型 | 含义 | 由用户提供 | 备注 |
---|---|---|---|---|---|
name | 必须 | str | pod的名称 | 用户提供 | 在同一个namspace中唯一 |
labels | 不必须 | map[str]str | 用户自主标识的k/y键值对 | 由用户提供 | 多用于service与pod或者replication controller与pod的匹配 |
uid | 必须 | str | 系统唯一标识pod实例的uid | 非用户提供 | z只读属性,由系统注入 |
namespace | 不必须 | str | pod所在的namespace | 由用户提供 | 若为空,则默认为default |
定义容器资源
字段 | 是否必须 | 类型 | 含义 | 由用户提供 | 备注 |
---|---|---|---|---|---|
containers[] | 必须 | str | list | 要在pod内启动所有的container | 由用户提供 |
containers[].name | 必须 | str | 容器名 | 由用户提供 | 唯一标识容器,在同一个pod内必须独一无二 |
containers[].image | 必须 | str | 容器使用的docker镜像名 | 由用户提供 | 无备注 |
containers[].command[] | 不必须 | str list | 启动docker容器时运行的命令 | 由用户提供 | 无备注 |
containers[].workingDir | 不必须 | str | 命令在docker容器内执行的初始工作目录 | 由用户提供 | 一旦设置无法更新,默认是Docker default |
containers[].volumeMounts[] | 不必须 | list | 暴露给容器且能够挂载到docker容器文件系统上的所有volume | 由用户提供 | 无备注 |
containers[].volumeMounts[].name | 不必须 | str | volume名 | 由用户提供 | 代挂载volume的名字,该字段必须与在volume[]中定义的name匹配 |
containers[].volumeMounts[].mountPath | 不必须 | str | volume在容器内的挂载点路径 | 由用户提供 | 该路径必须是绝对路径且长度不能超过512个字符 |
containers[].volumeMounts[].readOnly | 不必须 | boolean | 标识该volume是否是只读的 | 由用户提供 | 默认值是dalse,即可读可写 |
定义容器端口和环境
字段 | 是否必须 | 类型 | 含义 | 由用户提供 | 备注 |
---|---|---|---|---|---|
containers[].ports[] | 非必须 | list | 容器打开的所有端口 | 由用户提供 | 一旦设置便无法更新 |
containers[].ports[].name | 非必须 | str | 端口名 | 由用户提供 | 在pdo内必须独一无二 |
containers[].ports[].containersPort | 必须 | int | 容器监听的端口号 | 由用户提供 | 1-65535 |
containers[].ports[].hostPort | 非必须 | int | 容器端口在宿主机上的端口映射 | 由用户提供 | 1-65535 |
containers[].ports[].protocol | 非必须 | str | 端口类型 | 由用户提供 | udp或者tcp,默认是tcp |
containers[].env[] | 非必须 | list | 在容器运行前设置的环境变量 | 由用户提供 | 是一组键值对 |
containers[].env[] | 非必须 | list | 在容器运行前设置的环境变量 | 由用户提供 | 无备注 |
containers.[].env[].value | 非必须 | str | 环境变量 | 由用户提供 | 无备注 |
重启策略
字段 | 是否必须 | 类型 | 含义 | 由用户提供 | 备注 |
---|---|---|---|---|---|
RestartPolicy | 非必须 | str | pod内容器重启策略 | 由用户提供 | 包含3种策略:Always,OnFailure和Never |
volume配置
字段 | 是否必须 | 类型 | 含义 | 由用户提供 | 备注 |
---|---|---|---|---|---|
volumes[] | 非必须 | list | pod内由容器间共享的所有volume | 由用户提供 | 无备注 |
volumes[].name | 非必须 | str | volume名 | 由用户提供 | 无备注 |
volumes[].VolumeSource | 非必须 | object | 代挂载volume的种类 | 由用户提供 | 包括HostPath,EmptDir,GcePersistentDist等多种类型 |
volumes[].source.emptyDir | 非必须 | object | emptyDir类型volume | 由用户提供 | 默认的volume类型,代表挂载的volume是一个风险pod生命周期的您是目录,emotyDir的值是一个空对象,即:empuytDir:{} |
volume[].source.hostPath | 非必须 | object | hostPath类型volume | 由用户提供 | 代表挂载的volume是个以及存在与宿主机上的目录。需要指定volumes[].source.hostPath.path |
volumes[].source.hostPath.path | 非必须 | str | 宿主机上一个暴露给容器的现存目录的路径 | 由用户提供 | 无备注 |
volumes[].source.gcePersistentDisk | 非必须 | object | GCEPersistentDisk类型的volume | 由用户提供 | 无备注 |
volumes[].source.gitRepo | 非必须 | object | gitRepo类型volume | 由用户提供 | 代表某个特定版本的git仓库的url |
volumes[].source.secret | 非必须 | object | secret类型的volume | 不确定 | 用户可以自行提供secret,亦可以采用系统生成的默认secret |
pod使用的dns
字段 | 是否必须 | 类型 | 含义 | 由用户提供 | 备注 |
---|---|---|---|---|---|
DNSPolicy | 非必须 | list | 定义pod使用DNS的策略 | 由用户提供 | 有两种选择:ClusterFirst和Default,前者代表pod首先使用集群dns,否则代表pod使用kubelet设置的dns。默认值是ClusterFirst |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律