deployment

常见命令

  1. 创建一个deployment
kubectl create deployment my-tomcat --image=tomcat:9.0.55
# my-tomcat 表示pod的名称,--image表示镜像的地址
  1. 查看一下deployment
kubectl get deployment
  1. 删除deployment
kubectl detele deployment my-tomcat
  1. 查看pod打印的日志
kubectl logs <pod名称>
  1. 使用exec可以在pod的容器中执行命令
kubectl exec <pod名称> -- env #使用env命令查看环境变量
kubectl exec <pod名称> -- ls / #查看容器的根目录下面内容
kubectl exec <pod名称> -- sh #进入pod容器内部并非执行bash命令,如果想退出容器可以使用exit命令

多副本

  1. 创建3个副本
[ops@master ~]$ kubectl create deployment mynginx2 --image=nginx:1.26-alpine3.20 --replicas=3
[ops@master ~]$ kubectl get pod
NAME                        READY   STATUS    RESTARTS      AGE
mynginx2-6f8df44986-c767h   1/1     Running   0             25s
mynginx2-6f8df44986-grn98   1/1     Running   0             25s
mynginx2-6f8df44986-lw69k   1/1     Running   0             25s

扩缩容

  1. 扩容到5个pod
[ops@master ~]$ kubectl scale --replicas=5 deployment mynginx2
deployment.apps/mynginx2 scaled
[ops@master ~]$ kubectl get pod
NAME                        READY   STATUS    RESTARTS      AGE
mynginx2-6f8df44986-25j5z   1/1     Running   0             4s
mynginx2-6f8df44986-c767h   1/1     Running   0             3m15s
mynginx2-6f8df44986-grn98   1/1     Running   0             3m15s
mynginx2-6f8df44986-gs2s7   1/1     Running   0             4s
mynginx2-6f8df44986-lw69k   1/1     Running   0             3m15s
  1. 缩到3个pod
[ops@master ~]$ kubectl scale --replicas=3 deployment mynginx2
deployment.apps/mynginx2 scaled
[ops@master ~]$ kubectl get pod
NAME                        READY   STATUS    RESTARTS      AGE
mynginx2-6f8df44986-grn98   1/1     Running   0             4m49s
mynginx2-6f8df44986-gs2s7   1/1     Running   0             98s
mynginx2-6f8df44986-lw69k   1/1     Running   0             4m49s
[ops@master ~]$ 

版本回滚

  1. 查看历史版本
[ops@master ~]$ kubectl rollout history deploy mynginx2
deployment.apps/mynginx2 
REVISION  CHANGE-CAUSE
1         <none>
  1. 回滚到上一个版本
[ops@master ~]$ kubectl rollout undo deploy mynginx
  • --to-revision参数可以指定回退的版本
[ops@master ~]$ kubectl rollout undo deploy mynginx --to-revision=2
posted @ 2024-09-27 15:13  小肚腩吖  阅读(1)  评论(0编辑  收藏  举报