码迷,mamicode.com
首页 > 其他好文 > 详细

k8s用kubectl管理应用升级,服务发布与回滚,扩缩容

时间:2019-07-08 13:35:14      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:out   bsp   roo   server   res   bec   dep   undo   docker   

应用升级

Kubectl set image --help 有案例指定新版本

[root@k8s-master ~]# kubectl set image deployment/nginx nginx=nginx:1.11

升级之后他会将所有版本进行替换,describe来查看版本

[root@k8s-master ~]# kubectl get pods

NAME                       READY     STATUS    RESTARTS   AGE

busybox-5d4f595646-dzjv4   1/1       Running   0          2d

nginx-76c4c6d6d8-5w825     1/1       Running   0          2m

nginx-76c4c6d6d8-bh2sm     1/1       Running   0          2m

nginx-76c4c6d6d8-cwhw5     1/1       Running   0          1m

 

describe来查看版本,看到版本已经升级为1.11版本了,另外下面还有他的输出信息

[root@k8s-master ~]# kubectl describe po/nginx-76c4c6d6d8-cwhw5

 nginx:

    Container ID:   docker://ca046dd27d86bc10f330131be7ba5b91b14cb555c5d9677bb23f481e4e69aa67

    Image:          nginx:1.11

 

第二种修改应用版本===可以使用edit

直接进行编辑就行

[root@k8s-master ~]# kubectl edit deploy/nginx

找到image直接修改进行保存,升级之后他会将所有版本进行替换,用describe来查看版本

 

等启动之后查看pod重启新的镜像已经运行了

[root@k8s-master ~]# kubectl get pods

NAME                       READY     STATUS    RESTARTS   AGE

busybox-5d4f595646-dzjv4   1/1       Running   0          2d

nginx-7454cd89d8-fpncj     1/1       Running   0          5m

nginx-7454cd89d8-gdz8c     1/1       Running   0          4m

nginx-7454cd89d8-tlngj     1/1       Running   0          5m

describe查看Pod镜像信息

[root@k8s-master ~]# kubectl describe po/nginx-7454cd89d8-tlngj

nginx:

    Container ID:   docker://6768df2391defe44097e3ce2a857529ec614d49962181c1cf541c1bbc6dbce08

Image:          nginx:1.15

 

node端直接访问查看版本

[root@k8s-node1 ~]# curl -I 10.10.10.173:88

HTTP/1.1 200 OK

Server: nginx/1.15.12

Date: Mon, 08 Jul 2019 04:23:42 GMT

 

查看版本升级信息

[root@k8s-master ~]# kubectl rollout history deploy/nginx

deployments "nginx"

REVISION  CHANGE-CAUSE

1         <none>

2         <none>

3         <none>

记录版本信息状态,便于回滚

[root@k8s-master ~]# kubectl set image deployment/nginx nginx=nginx:1.16 --record

[root@k8s-master ~]# kubectl rollout history deploy/nginx

deployments "nginx"

REVISION  CHANGE-CAUSE

1         <none>

2         <none>

3         <none>

4         kubectl set image deployment/nginx nginx=nginx:1.16 --record=true

进行回滚用rollout undo,默认恢复到上一个版本也就是1.15

[root@k8s-master ~]# kubectl rollout undo deploy/nginx

默认少一个3,也就是回到上次第三次版本了

[root@k8s-master ~]# kubectl rollout history deploy/nginx

deployments "nginx"

REVISION  CHANGE-CAUSE

1         <none>

2         <none>

4         kubectl set image deployment/nginx nginx=nginx:1.16 --record=true

5         <none>

[root@k8s-master ~]# kubectl describe po/nginx-7454cd89d8-txjpm

Containers:

  nginx:

    Container ID:   docker://f17b88c301d61b8c75a46cba84d97c285f5d61886c081b3cfc9c0668e5cbf4e3

    Image:          nginx:1.15

 

业务量突然增加,我们需要增加副本

[root@k8s-master ~]# kubectl scale deploy/nginx --replicas=10

deployment "nginx" scaled

[root@k8s-master ~]# kubectl get pod

NAME                       READY     STATUS    RESTARTS   AGE

busybox-5d4f595646-dzjv4   1/1       Running   0          2d

nginx-7454cd89d8-4cct8     1/1       Running   0          19s

nginx-7454cd89d8-75tvg     1/1       Running   0          7m

nginx-7454cd89d8-7v5qp     1/1       Running   0          1m

nginx-7454cd89d8-dtsgq     1/1       Running   0          19s

nginx-7454cd89d8-hjcpw     1/1       Running   0          7m

nginx-7454cd89d8-mhhww     1/1       Running   0          19s

nginx-7454cd89d8-txjpm     1/1       Running   0          7m

nginx-7454cd89d8-vkmjn     1/1       Running   0          19s

nginx-7454cd89d8-z8dbn     1/1       Running   0          19s

nginx-7454cd89d8-zn8pm     1/1       Running   0          1m

 

业务量下降我们进行缩容

[root@k8s-master ~]# kubectl scale deploy/nginx --replicas=5

[root@k8s-master ~]# kubectl get pod

NAME                       READY     STATUS    RESTARTS   AGE

busybox-5d4f595646-dzjv4   1/1       Running   0          2d

nginx-7454cd89d8-75tvg     1/1       Running   0          8m

nginx-7454cd89d8-7v5qp     1/1       Running   0          3m

nginx-7454cd89d8-hjcpw     1/1       Running   0          8m

nginx-7454cd89d8-txjpm     1/1       Running   0          8m

nginx-7454cd89d8-zn8pm     1/1       Running   0          3m

要是不需要这些资源或者换项目了

直接用delete=======删除deploy还有service

[root@k8s-master ~]# kubectl delete deploy/nginx

deployment "nginx" deleted

[root@k8s-master ~]# kubectl delete svc/nginx-service

查看资源已经删除

[root@k8s-master ~]# kubectl get all

k8s用kubectl管理应用升级,服务发布与回滚,扩缩容

标签:out   bsp   roo   server   res   bec   dep   undo   docker   

原文地址:https://www.cnblogs.com/zc1741845455/p/11150518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!