k8s更新一个应用

在K8S集群中创建一个nginx应用

  • 功能需求

      在K8S中更新一个应用(以nginx举例)

  • 实验环境

1台master+2台worknode

已经有部署一个名为helloNginx的应用,并通过NodePort的方式暴露出service给外部访问

 

 

  • 操作步骤

 

方式1: 使用yaml文件更新deployment以及

#kubectl apply -f helloNginx-v2.0.yaml --record=true

//--record=true 表示记录rollou history

方式2: 使用命令更新

#kubectl set image helloNginx nginx=nginx:1.18

  • 回滚操作 

//查看rollout history 

#kubectl rollout history deplyement helloNginx

//回滚到前一个版本

#kubectl rollout undo deplyement  helloNginx

//回滚到指定的revisionID=2的历史版本

#kubectl rollout undo deplyement  helloNginx --to-revision=2 

  • 应用水平扩容和缩容 

//水平扩容(增加机器,部署更多的副本,原来3个,现在10个副本)

#kubectl scale deplyement helloNginx --replicas=10

//水平缩容(原来3个副本,现在减少为1个)

#kubectl scale deplyement helloNginx --replicas=1

  • 删除应用 

//删除deployment

#kubectl delete deployment helloNginx

//删除service

#kubectl delete service helloNginx

 

 

 

 

posted @ 2022-04-06 13:42  VinceGod  阅读(169)  评论(0)    收藏  举报