kubernetes 学习笔记3

kubernetes  自动发布和回滚

deployment 引入的目的是为了更好的解决pod的编排问题。
 
  • 创建一个deployment对象来生成对应的replica set 并完成 pod副本的创建过程
  • 检查deployment的状态来看部署动作是否完成(pod副本的数量是否达到预期的值)
  • 更新deployment以创建新的pod(比如镜像升级)
  • 如果当前deployment不稳定,则回滚至一个早先的deployment版本
创建deployment
$ kubectl create -f docs/user-guide/nginx-deployment.yaml --record
deployment "nginx-deployment” created
查看正在创建或者正在更新的deplyment
$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         0         0            0           1s
$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         3         3            3           18s
查看replica set 和 pod
$ kubectl get rs
NAME                          DESIRED   CURRENT   AGE
nginx-deployment-2035384211   3         3         18s 
查看生成的各个pod的归属关系
$ kubectl get pods --show-labels
NAME                                READY     STATUS    RESTARTS   AGE       LABELS
nginx-deployment-2035384211-7ci7o   1/1       Running   0          18s       app=nginx,pod-template-hash=2035384211
nginx-deployment-2035384211-kzszj   1/1       Running   0          18s       app=nginx,pod-template-hash=2035384211
nginx-deployment-2035384211-qqcnn   1/1       Running   0          18s       app=nginx,pod-template-hash=2035384211
查看deployment的状态
$ kubectl rollout status deployment/nginx-deployment
deployment "nginx-deployment" successfully rolled out
更新deployment
 
当deployment 里面的pod模版更改了
                         label更新了
                         容器镜像改变了,那么会触发deployment重新发布,如果deployment进行扩展,那么不会触发deployment
 
可以直接写命令进行更改
kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
deployment "nginx-deployment" image updated
也可以进行编辑进行更改
$ kubectl edit deployment/nginx-deployment
deployment "nginx-deployment" edited
查看发布的状态
$ kubectl rollout status deployment/nginx-deployment
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
deployment "nginx-deployment" successfully rolled out
如果发布成功
$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         3         3            3           36s
$ kubectl get rs
NAME                          DESIRED   CURRENT   AGE
nginx-deployment-1564180365   3         3         6s
nginx-deployment-2035384211   0         0         36s
$ kubectl get pods
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-1564180365-khku8   1/1       Running   0          14s
nginx-deployment-1564180365-nacti   1/1       Running   0          14s
nginx-deployment-1564180365-z9gth   1/1       Running   0          14s
更新pod,我们只需更新deployment里面的templement
当我们更新deployment时候,当有合适的pod产生的时候,k8s才会删除老的pod,当老的pod被删除足够多时,才会继续产生新的pod
 
 
deployment 回滚
查看deployment详细信息
$ kubectl describe deployment
查看deployment的发布历史
$ kubectl rollout history deployment/nginx-deployment
可以回滚至任一个之前的版本
$ kubectl rollout undo deployment/nginx-deployment
deployment "nginx-deployment" rolled back
$ kubectl rollout undo deployment/nginx-deployment --to-revision=2
deployment "nginx-deployment" rolled back
扩展deployment

ou can scale a Deployment by using the following command:

$ kubectl scale deployment nginx-deployment --replicas 10
deployment "nginx-deployment" scaled
$ kubectl autoscale deployment nginx-deployment --min=10 --max=15 --cpu-percent=80
deployment "nginx-deployment" autoscaled
暂停或者回复一个deployment
$ kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1; kubectl rollout pause deployment/nginx-deployment
deployment "nginx-deployment" image updated
deployment "nginx-deployment" paused
deployment的状态
deployment为processing状态的情况为:
1.deployment正在创建rs
2.deployment正在扩展或者删除rs
 
deploymen为什么会失败
  • Insufficient quota
  • Readiness probe failures
  • Image pull errors
  • Insufficient permissions
  • Limit ranges
  • Application runtime misconfiguration
posted @ 2017-03-01 18:20 leidaxia 阅读(...) 评论(...) 编辑 收藏