创建deploy

  1. #单副本
  2. kubectl create deployment mytomcat --image=tomcat:8.5.68
  3. #多副本
  4. kubectl create deployment my-dep --image=nginx --replicas=3
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. labels:
  5. app: my-dep
  6. name: my-dep
  7. spec:
  8. replicas: 3
  9. selector:
  10. matchLabels:
  11. app: my-dep
  12. template:
  13. metadata:
  14. labels:
  15. app: my-dep
  16. spec:
  17. containers:
  18. - image: nginx
  19. name: nginx

查询deploy

  1. kubectl get deploy

删除deploy

  1. kubectl delete deploy mytomcat

扩缩容

  1. #命令行方式
  2. kubectl scale --replicas=5 deployment/my-dep
  3. #配置文件方式
  4. kubectl edit deployment my-dep

滚动更新

  1. #查看pod镜像-作为对比
  2. kubectl get deploy my-dep -oyaml
  3. #滚动更新
  4. kubectl set image deployment/my-dep nginx=nginx:1.16.1 --record

版本回退

  1. #历史记录
  2. kubectl rollout history deployment/my-dep
  3. #查看某个历史详情
  4. kubectl rollout history deployment/my-dep --revision=2
  5. #回滚(回到上次)
  6. kubectl rollout undo deployment/my-dep
  7. #回滚(回到指定版本)
  8. kubectl rollout undo deployment/my-dep --to-revision=2