CFN Cloud
Cloud Future New Life
en zh
2025-10-04 · 0 次浏览

Pod: 容器的最小调度单元

理解 Pod 的共享网络、存储与生命周期。

Pod 是 Kubernetes 的最小调度单位。一个 Pod 可以包含一个或多个容器,它们共享网络与存储。

什么时候需要多容器

  • sidecar:日志/代理/监控
  • 共享数据:同一个 emptyDir
  • 生命周期绑定:一起启动和销毁

示例 Pod

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
    - name: app
      image: nginx:1.25
      ports:
        - containerPort: 80
    - name: sidecar
      image: busybox:1.36
      command: ["sh", "-c", "while true; do echo ok; sleep 5; done"]

常用命令

kubectl get pods
kubectl describe pod demo-pod
kubectl logs demo-pod -c app

实操要点

  • 先做快速盘点:kubectl get nodeskubectl get pods -Akubectl get events -A
  • 对比“期望状态”和“实际状态”,kubectl describe 往往能解释漂移或失败原因。
  • 名称、Label、Selector 要一致,避免 Service 或控制器找不到 Pod。

快速检查清单

  • 资源定义与业务意图一致。
  • Namespace、权限、镜像与环境匹配。
  • 上线前具备健康探针与可观测日志。

参考链接