
pod是容器化的基础,好比大楼的地基。
Pod跟容器的关系
类比一下:
POD: 物理机
容器: 物理机上的一个进程;
容器只是Pod的一个普通字段。
Pod的作用范围
跟容器的linux namespace相关的东西一定是Pod级别的,pod。
比如:
网络:  hostAliases : 写入/ect/hosts内容 ;  sharePrcessNamespace: 共享PID 空间
存储: vlume
安全:   secret
调度: NodeSelector  用户指定pod跟node的对应关系 ; NodeName 标识调度过了,可用来调试pod;
Pod的Container元素
containers和initContainers关系
initContainers先于containers创建 ; sidecar实现的重要基础;按照定义的顺序来执行;
containers: 容器定义
元素如下:
| 元素 | 说明 | 
|---|---|
| image | 镜像地址 | 
| ports | 端口定义 | 
| command | 启动指令 | 
| workingDir | 工作目录 | 
| volumeMounts | 数据卷挂载 | 
| imagePullPolicy | 镜像拉取策略 | 
| lifecycle | 容器生命周期钩子定义 preStop postStart | 
Pod的问题定位
通过 spec.status.phase来定位;
pending:创建过程中,由于某些原因调度失败
running:   正常运行中
succeed:  一次性调度成功
failed:  调度失败
unknow: 未知
还可以结合 condition来定位:
unscheduled: 没有调度
podScheduled: pod调度中
ready: 准备好
initalized: 初始化中
其它指令
attach: 进入容器的tty 命令行,如果有安装的话;
kubectl attach -it youpodname -c youcontainername
小结
围绕pod的核心字段做了介绍。
示例配置文件:
apiVersion: apps/v1
kind: Pod
metadata:
  name: my-pod
spec:
  shareProcessNamespace: true
  nodeSelector:
    diskType: ssd
  hostAliases:
  - ip: "10.10.10.9"
    hostnames:
    - "a.b.com"
    - "ac.b.com"
  lifecycle:
    postStart:
      exec:
        command: ["/bin/bash","-c","echo 'xxxx'> /usr/share/messages"]
    preStop:
      exec:
        command: ["/usr/sbin/nginx","-t","quit"]

原创不易,关注诚可贵,转发价更高!转载请注明出处,让我们互通有无,共同进步,欢迎沟通交流。