kubernetes学习之 Deployment:声明式地升级应用

更新运行在pod内的应用程序

  • 删除旧版本pod,使用新版本pod替换
  • 先创建新版本pod,再删除旧版本pod

 

使用ReplicationController实现自动的滚动升级

使用下面的命令实现滚动升级

kubectl rolling-update OLD_CONTROLLER_NAME ([NEW_CONTROLLER_NAME] --image=NEW_CONTAINER_IMAGE | -f NEW_CONTROLLER_SPEC)
 

# Update the pods of frontend-v1 to frontend-v2 by just changing the image, and switching the
# name of the replication controller.
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2

 

使用Deployment声明式地升级应用

  • 创建一个Deployment

----------------------

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

---------------------

kubectl create -f deployment.yaml --record

# Watch the rollout status of a deployment
kubectl rollout status deployment nginx

  • 升级Deployment

触发滚动升级

kubectl set image deployment/nginx  nginx=nginx:1.16.1 --record
 

回滚Deployment

kubectl rollout undo deployment kubia

显示Deployment的滚动升级历史

kubectl rollout history deployment nginx

----

daemonsets "<nginx>"
REVISION        CHANGE-CAUSE
1               ...
2               ...

----

回滚到一个特定的Deployment版本

# Specify the revision number you get from Step 1 in --to-revision
kubectl rollout undo deployment  nginx --to-revision=<revision>

 

控制滚动升级速率

滚动升级策略的maxSurge和maxUnavailable

spec:
 replicas: 3
 strategy:
    type: RollingUpdate
    rollingUpdate:
        maxSurge: 2 # how many pods we can add at a time
        maxUnavailable: 0 # maxUnavailable define how many pods can be
 # unavailable during the rolling update

暂停滚动升级

kubectl rollout pause deployment nginx

回复滚动升级

kubectl rollout resume deployment nginx

使用暂停功能来停止滚动升级

 

阻止出错版本的滚动升级

了解minReadySeconds的用处

.spec.minReadySeconds is an optional field (with default value of 600s) that specifies the minimum number of seconds for which a newly created Pod should be ready without any of its containers crashing, for it to be considered available. This defaults to 0 (the Pod will be considered available as soon as it is ready). To learn more about when a Pod is considered ready, see Container Probes.

配置就绪探针来阻止全部v3版本的滚动部署

apiVersion: v1
kind: Pod
metadata:
 name: nodedelayed
spec:
 containers:
   - image: afakharany/node_delayed
     name: nodedelayed
     ports:
       - containerPort: 3000
         protocol: TCP
     readinessProbe:
       httpGet:
         path: /
         port: 3000
       timeoutSeconds: 2

 

使用kuber apply 升级Deployment

Apply a configuration to a resource by filename or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'.

$ kubectl apply (-f FILENAME | -k DIRECTORY)

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值