deployment样本文件
$ cat hello-world.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
namespace: dev
labels:
app: hello-world
spec:
replicas: 3
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: hello-world:v1
imagePullPolicy: IfNotPresent
说明:
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
或者
$ 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 <none>
回滚指定版本
kubectl rollout undo deployment hello-world --to-revision=1 -n dev
查看升级部署状态
$ kubectl rollout status deployment hello-world -n dev
原文地址:http://blog.51cto.com/2759492/2084484
时间: 2024-11-08 17:42:32