deployment样本文件
$ cat hello-world.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
namespace: dev
labels:
app: hello-world
spec:
revisionHistoryLimit: 10
replicas: 3
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: hello-world:v1
imagePullPolicy: IfNotPresent
说明:
revisionHistoryLimit: 10 记录下达指令个数,配合--record使用,--record告知 Kubernetes 记录此次下达的指令
minReadySeconds: 5 Kubernetes 会等待设定的时间后才继续进行升级流程
maxSurge: 1 表示滚动升级前先启动1个pod
maxUnavailable: 1 表示滚动升级时允许的最大Unavailable的pod个数,一次升级数量
maxSurge >= maxUnavailable
创建deployment
$ kubectl create -f hello-world.yaml
查看deployment
$ kubectl describe deployment hello-world -n dev
Name: hello-world
Namespace: dev
CreationTimestamp: Fri, 09 Mar 2018 10:09:15 +0800
Labels: app=hello-world
Annotations: deployment.kubernetes.io/revision=1
Selector: app=hello-world
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=hello-world
Containers:
hello-world:
Image: hello-world:v1
Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: hello-world-5cc47c955f (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 4s deployment-controller Scaled up replica set hello-world-5cc47c955f to 3
升级deployment
$ kubectl set image deployment hello-world hello-world=hello-world:v2 -n dev --record
或者
$ kubectl edit deployment hello-world -n dev
终止升级
$ kubectl rollout pause deployment hello-world -n dev
继续升级
$ kubectl rollout resume deployment hello-world -n dev
回滚上一个版本
$ kubectl rollout unto deployment hello-world -n dev
查看deployment版本
$ kubectl rollout history deployment hello-world -n dev
deployments "hello-world"
REVISION CHANGE-CAUSE
1 <none>
2 kubectl set image deployment hello-world hello-world=hello-world:v2 --record=true
3 kubectl set image deployment hello-world hello-world=hello-world:v3 --record=true
4 kubectl set image deployment hello-world hello-world=hello-world:v4 --record=true
5 kubectl set image deployment hello-world hello-world=hello-world:v5 --record=true
回滚指定版本
$ kubectl rollout undo deployment hello-world --to-revision=3 -n dev
查看升级部署状态
$ kubectl rollout status deployment hello-world -n dev
deployment "hello-world" successfully rolled out
升级过程,动态显示,通常情况下用以下命令,捕获升级过程信息;
$ kubectl set image deployment hello-world hello-world=hello-world:v2 -n dev --record && kubectl rollout status deployment hello-world
deployment "hello-world" image updated
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for rollout to finish: 1 old replicas are pending termination...
Waiting for rollout to finish: 1 old replicas are pending termination...
Waiting for rollout to finish: 1 old replicas are pending termination...
Waiting for rollout to finish: 2 of 3 updated replicas are available...
deployment "hello-world" successfully rolled out
转载于:https://blog.51cto.com/2759492/2084484