POD--基本单位


2021年3月22日 11:52     admin

创建Pod

  1. #创建pod的yml文件
  2. vim examplepod.yml
  3. #内容:
  4. apiVersiapiVon:v1
  5. kind:Pod
  6. metadata:
  7. name:examplepod
  8. spec:
  9. containers:
  10. - name: examplepod-container
  11. image: busybox
  12. imagePullPolicy: IfNotPresent
  13. command: ['sh','-c']
  14. args: ['echo "hello world!";sleep 3600']
  15. ------------------------------------------------------------
  16. 参数含义:
  17. apiVersiapiVon:表示使用的API版本
  18. kind:表示要创建的资源对象
  19. metadata:表示该资源对象的元数据。name表示当前资源的名称
  20. spec: 表示该资源对象的具体设置
  21. containers: 表示容器的集合
  22. name 要创建的容器名称
  23. image: 容器的镜像地址
  24. imagePullPolicy: 镜像的下载策略:
  25. Always:不管镜像是否存在都会进行一次拉取
  26. Never: 不管镜像是否存在都不会拉取
  27. IfNotPresent:只有镜像不存在时,才会进行拉取
  28. command: 容器的启动命令列表
  29. args: 启动参数列表

  1. #创建Pod
  2. kubectl apply -f examplepod.yml

查询Pod

  1. #查询当前运行的所有Pod
  2. kubectl get pods #(默认命名空间为default)
  3. kubectl get pods -n <namespace>

  1. kubectl get pods -A #(所有命名空间)

  1. #查询指定Pod
  2. kubectl get pods [Pod名称]

  1. #持续监控
  2. kubectl get pods [Pod名称] -w

  1. #查看Pod的改要信息
  2. kubectl get pods -o wide

  1. #查看Pod的详情
  2. kubectl describe pods [Pod名称]

  1. #查看Pod的日志
  2. kubectl logs [Pod名称]


修改Pod

  1. kubectl replace -f [pod模板]
  2. kubectl replace -f [pod模板] --force #强制,相当于重建Pod

删除Pod

  1. kubectl delete pods [Pod名称] #删除单个Pod
  2. kubectl delete -f [模板文件] #删除模板文件中的Pod

查看Pod配置

  1. kubectl get pods [Pod名称] -o yaml
  2. kubectl get pods [Pod名称] -o json