k8s-pod定义详解

211 阅读2分钟
apiVersion: v1   #版本号
kind: Pod
metadata:   #元数据
  name: string       # pod名称
  namespace: string  # 所属命名空间
  labels: #自定义标签列表
    - name: string
  annotations: # 自定义注解列表
    - name: string
spec: # pod容器的定义
  containers:  # pod容器的列表
    - name: string  # 容器名称
      image: string  # 镜像名称
      imagePullPolicy: Always # [Always 总是拉去 | Never  只使用本地| IfNotPresent 本地不存在拉去]    默认always
      command: [string]  # 容器启动命令
      args: [string]  # 容器启动命令参数列表
      workingDir: string  # 容器工作目录
      volumeMounts:  # 挂载到容器内部的存储卷配置
        - name: string # 引用pod定义的共享存储卷名称,需使用volumens[]部分定义的共享存储卷
          mountPath: string   # 存储卷在容器内挂载的绝对路径,
          readOnly: true #是否为只读模式,默认为读写模式
      ports: # 容器对外暴露的端口列表
        - name: string #端口名
          containerPort: 9000 #容器要监听的端口号
          hostPort: 9000  # 容器所在主机需要监听的端口号,默认与containerPort相同。设置hostport时,同一台宿主机无法启动该容器第二份副本
          protocol: TCP # 端口协议 默认tcp
      env:  #  容器运行钱设置的环境变量列表
        - name: string
          value: string
      resources: # 资源限制和资源请求的设置
        limits:
          cpu: string  #单位core数
          memory: string  #单位 MiB, Gib
        requests:
          cpu: string  #容器启动的初始可用数量
          memory: string
      livenessProbe: #存活检查 对pod内健康检查设置 exec httpGet tcpSocket三种 当探测无响应进几次之后,系统将自动重启容器
        exec:
          command: [string]
        httpGet:
          path: string
          port: number
          host: string
          scheme: string
          httpHeaders:
            - name: string
              value: string
        tcpSocket:
          port: number
        initialDelaySeconds: 0 #容器启动后首次探测时间
        timeoutSeconds: 0 #探测超时时间 默认1s
        periodSeconds: 0 # 定期检测时间 默认10秒一次
        successThreshold: 0  #成功的阈值
        failureThreshold: 0
      readinessProbe: # 就绪检查
        failureThreshold: 10
        initialDelaySeconds: 30
        periodSeconds: 10
        successThreshold: 1
        tcpSocket:
          port: 5900
        timeoutSeconds: 1
      securityContext: #安全上下文
        privileged: false
  restartPolicy: Always # [Always | Never 不重启 | OnFailure 非0退出重启] pod重启策略
  nodeSelector:  #object 设置node的label,pod将会调度到具有这些label的node上
    name: node1
  imagePullSecrets: # pull镜像时候的secret名称
    -  name: string
  hostNetwork: false # 是否使用主机网络模式,默认false
  volumes: # 共享存储卷列表
    - name: string # 共享存储卷名称  hostPath emptyDir configMap secret
      emptyDir: {}
      hostPath:
        path: string
      secret:
        secretName: string
        items:
          - key: string
            path: string
      configMap:
        name: string
        items:
          - key: string
            path: string