栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

K8s系列之:Pod定义文件属性参数详解

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

K8s系列之:Pod定义文件属性参数详解

K8s系列之:Pod定义文件属性参数详解

一、Pod定义文件二、Pod定义文件各属性参数详解

一、Pod定义文件

yaml格式的Pod定义文件的完整内容如下:

apiVersion: v1
kind: Pod
metadata:
  name: string
  namespace: string
  labels:
    - name: string
  annotations:
    - name: string
spec:
  containers:
  - name: string
    image: string
    imagePullPolicy: [Always | Never | IfNotPresent]
    command: [string]
    args: [string]
    workingDir: string
    volumeMounts:
    - name: string
      mountPath: string
      readOnly: boolean
    ports:
    - name: string
      containerPort: int
      hostPort: int
      protocol: string
    env:
    - name: string
      value: string
    resources:
      limits:
        cpu: string
        memory: string
      requests:
        cpu: string
        memory: string
    livenessProbe:
      exec:
        command: [string]
      httpGet:
        path: string
        port: number
        host: string
        schema: string
        httpHeaders:
        - name: string
          value: string
        tcpSocket:
          prot: number
        initialDelaySeconds: 0
        timeoutSeconds: 0
        periodSeconds: 0
        successThreshold: 0
        failureThreshold: 0
      securityContext:
        privileged: false
    restartPolicy: [Always | Never | OnFailure]
    nodeSelector: object
    imagePullSecrets:
    - name: string
    hostNetwork: false
    volumes:
    - name: string
      empthDir: {}
      hostPath:
        path: string
      secret:
        secretName: string
        items:
        - key: string
          path: string
      configMap:
        name: string
        items:
        - key: string
          path: string
二、Pod定义文件各属性参数详解

对Pod各属性的详细说明如下表所示:

属性名称取值类型是否必须取值说明
apiVersionStringRequired版本号,例如v1
kindStringRequiredPod
metadataObjectRequired元数据
metadata.nameStringRequiredPod的名称
metadata.namespaceStringRequiredPod所属的命名空间
metadata.labels[]List自定义标签列表
metadata.annotation[]List自定义注解列表
SpecObjectRequiredPod中容器的详细定义
spec.containers[]ListRequiredPod中的容器列表
spec.containers[].nameStringRequired容器的名称
spec.containers[].imageStringRequired容器的镜像名称
spec.containers[].imagePullPolicyString获取镜像的策略,可选值包括:Always、Never、IfNotPresent,默认值为Always。Always:表示每次都尝试重新下载镜像。IfNotPresent:表示如果本地有该镜像,则使用本地的镜像,本地不存在时下载镜像。Never:表示仅使用本地镜像
spec.containers[].command[]List容器的启动命令列表,如果不指定,则使用镜像打包时使用的启动命令
spec.containers[].args[]List容器的启动命令参数列表
spec.containers[].workingDirString容器的工作目录
spec.containers[].volumeMounts[]List挂载到容器内部的存储卷配置
spec.containers[].volumeMounts[].nameString引用Pod定义的共享存储卷的名称,需使用volumes[]部分定义的共享存储卷名称
spec.containers[].volumeMounts[].mountPathString存储卷在容器内Mount的绝对路径,应少于512个字符
spec.containers[].volumeMounts[].readOnlyBoolean是否为只读模式,默认值为读写模式
spec.containers[].ports[]List容器需要暴漏的端口号列表
spec.containers[].ports[].nameString端口的名称
spec.containers[].ports[].containerPortInt容器需要监听的端口号
spec.containers[].ports[].hostPortInt容器所在主机需要监听的端口号,默认与containerPort相同。设置hostPort时,同一台宿主机无法启动该容器的第2份副本
spec.containers[].protocolString端口协议,支持TCP和UDP,默认值为TCP
spec.containers[].env[]List容器运行前需设置宕环境变量列表
spec.containers[].env[].nameString环境变量的名称
spec.containers[].env[].valueString环境变量的值
spec.containers[].resourcesObject资源限制和资源请求的设置
spec.containers[].resources.limitsObject资源限制的设置
spec.containers[].resources.limits.cpuStringCPU限制,单位为core数,将用于docker run --cpu-shares参数
spec.containers[].resources.limits.memoryString内存限制,单位可以为MiB/GiB等,将用于docker run --cpu-shares参数
spec.containers[].resources.requestsObject资源限制的设置
spec.containers[].resources.requests.cpuStringCPU请求,单位为core数,容器启动的初始可用数量
spec.containers[].resources.requests.memoryString内存请求,单位可以为MiB、GiB等,容器启动的初始可用数量
spec.volumes[]List在该Pod上定义的共享存储卷列表
spec.volumes[].nameString共享存储卷的名称,在一个Pod中每个存储卷定义一个名称。容器定义部分的containers[].volumeMounts[].name将引用该存储卷的名称。Volume的类型包括:emptyDir、hostPath、secret、configMap等,可以定义多个volume,每个volume的name保持唯一。
spec.volumes[].emptyDirObject类型为emptyDir的存储卷,表示与Pod同生命周期的一个临时目录,其值为一个空对象:emptyDir:{}
spec.volumes[].hostPathObject类型为hostPath的存储卷,表示挂载Pod所在宿主机的目录,通过volumes[].hostPath.path指定
spec.volumes[].hostPath.pathStringPod所在主机的目录,将被用于容器中mount的目录
spec.volumes[].secretObject类型为secret的存储卷,表示挂载集群预定义宕secret对象到容器内部
spec.volumes[].configMapObject类型为secret的存储卷,表示挂载集群预定义的configMap对象到容器内部
spec.volumes[].livenessProbeObject对Pod内各容器健康检查的设置,当探测无响应几次之后,系统将自动重启该容器。可以设置的方法包括:exec、httpGet和tcpSoccket。对一个容器需设置一种健康检查方法
spec.volumes[].livenessProbe.execObject对Pod内各容器健康检查的设置,exec方式
spec.volumes[].livenessProbe.exec.command[]Stringexec方式需要指定的命令或者脚本
spec.volumes[].livenessProbe.httpGetObject对Pod内各容器健康检查的设置,HTTPGet方式,需要指定Path、port
spec.volumes[].livenessProbe.tcpSocketObject对Pod内各容器健康检查的设置,tcpSocket方式
spec.volumes[].livenessProbe.initialDelaySecondsNumber容器启动完成后首次探测的时间
spec.volumes[].livenessProbe.timeoutSecondsNumber对容器健康检查的探测等待响应的超时时间设置,单位为s,默认值为1s。超过该超时时间设置,将认为该容器不健康,将重启该容器
spec.volumes[].livenessProbe.periodSecondsNumber对容器健康检查的定期探测时间设置,单位为s,默认为10s探测一次
spec.restartPolicyStringPod重启策略,可选值为Always,OnFailure,默认值为Always。Always:Pod一旦终止运行,则无论容器是如何终止的,kubelet都将重启它。OnFailure:只有Pod以非零退出码终止时,kubelet才会重启该容器。如果容器正常结束(退出码为0),则kubelet将不会重启它。Never:Pod终止后,kubelet将退出码报告给Master,不会再重启该Pod
spec.nodeSelectorObject设置NodeSelector表示该Pod调度到包含这些label的Node上,以key:value格式指定
spec.imagePullSecretsObjectPull镜像时使用的secret名称,以name:secretkey格式指定
spec.hostNetworkBoolean是否使用主机网络模式,默认值为false,如果设置为true,则表示容器使用宿主机网络,不再使用Docker网桥,该Pod将无法在同一台宿主机上启动第2个副本
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/715723.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号