伸缩应用
#首先查看最原始的副本数为1
[root@localhost 101]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
app 10 10 10 10 8d
filled-oyster-heapster 1 1 1 1 3d22h
httpd 3 3 3 3 8d
nginx-app 1 1 1 1 54m
nginx-deployment 2 2 2 2 10d
orderly-ostrich-mychart 1 1 1 1 6d23h
prometheus-operator 1 1 1 0 3d22h
#我扩展为50个
[root@localhost 101]# kubectl scale --replicas=50 deployment/nginx-app
deployment.extensions/nginx-app scaled
[root@localhost 101]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
app 10 10 10 10 8d
filled-oyster-heapster 1 1 1 1 3d23h
httpd 3 3 3 3 8d
nginx-app 50 50 50 50 57m
nginx-deployment 2 2 2 2 10d
orderly-ostrich-mychart 1 1 1 1 6d23h
prometheus-operator 1 1 1 0 3d22h
#我收缩为30个
[root@localhost 101]# kubectl scale --replicas=30 deployment/nginx-app
deployment.extensions/nginx-app scaled
[root@localhost 101]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
app 10 10 10 10 8d
filled-oyster-heapster 1 1 1 1 3d23h
httpd 3 3 3 3 8d
nginx-app 30 30 30 30 58m
nginx-deployment 2 2 2 2 10d
orderly-ostrich-mychart 1 1 1 1 6d23h
prometheus-operator 1 1 1 0 3d22h
更新应用
#更新应用
[root@localhost 101]# kubectl set image deployment/nginx-app nginx-app=nginx:1.9.1
deployment.extensions/nginx-app image updated
#滚动升级的过程可以用 rollout 命令查看:
[root@localhost 101]# kubectl rollout status deployment/nginx-app
Waiting for deployment "nginx-app" rollout to finish: 2 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 2 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 2 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 3 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 3 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 3 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 4 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 4 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 5 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 5 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 5 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 5 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 6 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 6 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 6 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 6 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 6 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 7 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 7 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 7 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 8 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 8 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 8 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 9 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 9 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 9 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 9 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 9 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 10 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 10 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 10 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 10 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 10 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 11 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 11 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 11 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 12 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 12 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 14 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 14 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 14 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 19 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 19 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 21 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 21 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 21 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 23 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 23 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-app" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-app" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-app" rollout to finish: 29 of 30 updated replicas are available...
deployment "nginx-app" successfully rolled out
#验证pod是否改为1.9.1镜像了
[root@localhost 101]# kubectl describe pod nginx-app-6c5bf9d5bd-2t97x
Name: nginx-app-6c5bf9d5bd-2t97x
Namespace: default
Node: 10.0.60.51/10.0.60.51
Start Time: Fri, 23 Nov 2018 16:11:27 +0800
Labels: pod-template-hash=6c5bf9d5bd
run=nginx-app
Annotations: <none>
Status: Running
IP: 172.20.0.162
Controlled By: ReplicaSet/nginx-app-6c5bf9d5bd
Containers:
nginx-app:
Container ID: docker://83f2ae7cd822ce67f75a77759e7275ae131e798ff5b9297cd916b2b5ffd8b542
Image: nginx:1.9.1
Image ID: docker-pullable://nginx@sha256:2f68b99bc0d6d25d0c56876b924ec20418544ff28e1fb89a4c27679a40da811b
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 23 Nov 2018 16:11:29 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-97cmq (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-97cmq:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-97cmq
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 7m27s default-scheduler Successfully assigned default/nginx-app-6c5bf9d5bd-2t97x to 10.0.60.51
Normal Pulling 7m26s kubelet, 10.0.60.51 pulling image "nginx:1.9.1"
Normal Pulled 7m25s kubelet, 10.0.60.51 Successfully pulled image "nginx:1.9.1"
Normal Created 7m25s kubelet, 10.0.60.51 Created container
Normal Started 7m25s kubelet, 10.0.60.51 Started container
回滚
#查看版本历史
[root@localhost 101]# kubectl rollout history deployment/nginx-app
deployment.extensions/nginx-app
REVISION CHANGE-CAUSE
1 <none>
2 <none>
#回滚到上一次的版本
[root@localhost 101]# kubectl rollout undo deployment/nginx-app
deployment.extensions/nginx-app
#查看回滚状态
[root@localhost 101]# kubectl rollout status deployment/nginx-app
Waiting for deployment "nginx-app" rollout to finish: 11 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 11 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 12 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 12 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 12 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 13 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 14 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 14 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 15 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 16 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 17 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 18 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 19 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 19 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 19 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 19 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 20 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 21 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 21 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 22 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 23 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 23 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 23 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 23 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 24 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 25 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 26 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 27 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 28 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 29 out of 30 new replicas have been updated...
Waiting for deployment "nginx-app" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-app" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-app" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-app" rollout to finish: 29 of 30 updated replicas are available...
deployment "nginx-app" successfully rolled out
#验证是否已经回滚成功
[root@localhost 101]# kubectl describe pod nginx-app-58865955ff-z55vc
Name: nginx-app-58865955ff-z55vc
Namespace: default
Node: 10.0.60.51/10.0.60.51
Start Time: Fri, 23 Nov 2018 16:22:23 +0800
Labels: pod-template-hash=58865955ff
run=nginx-app
Annotations: <none>
Status: Running
IP: 172.20.0.187
Controlled By: ReplicaSet/nginx-app-58865955ff
Containers:
nginx-app:
Container ID: docker://a87b9f9feab73513d4a0b7c145c3580a4ee91566e16f0f1e008dc23fced82ad4
Image: nginx
Image ID: docker-pullable://nginx@sha256:d59a1aa7866258751a261bae525a1842c7ff0662d4f34a355d5f36826abc0341
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 23 Nov 2018 16:22:26 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-97cmq (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-97cmq:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-97cmq
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m46s default-scheduler Successfully assigned default/nginx-app-58865955ff-z55vc to 10.0.60.51
Normal Pulling 2m45s kubelet, 10.0.60.51 pulling image "nginx"
Normal Pulled 2m44s kubelet, 10.0.60.51 Successfully pulled image "nginx"
Normal Created 2m43s kubelet, 10.0.60.51 Created container
Normal Started 2m43s kubelet, 10.0.60.51 Started container