kubenete滚动升级版本动态扩缩容
一 滚动升级
根据资源编排文件部署一个Nginx应用,指定其版本为1.14,副本数为2个,对其升级为1.15,这个资源描述文件可以生成,然后修改副本数和nginx版本
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2021-05-26T14:05:03Z"
generation: 1
labels:
app: web
managedFields:
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:labels:
.: {}
f:app: {}
f:spec:
f:progressDeadlineSeconds: {}
f:replicas: {}
f:revisionHistoryLimit: {}
f:selector:
f:matchLabels:
.: {}
f:app: {}
f:strategy:
f:rollingUpdate:
.: {}
f:maxSurge: {}
f:maxUnavailable: {}
f:type: {}
f:template:
f:metadata:
f:labels:
.: {}
f:app: {}
f:spec:
f:containers:
k:{"name":"nginx"}:
.: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:resources: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:dnsPolicy: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
manager: kubectl
operation: Update
time: "2021-05-26T14:05:03Z"
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:deployment.kubernetes.io/revision: {}
f:status:
f:availableReplicas: {}
f:conditions:
.: {}
k:{"type":"Available"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
k:{"type":"Progressing"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
f:observedGeneration: {}
f:readyReplicas: {}
f:replicas: {}
f:updatedReplicas: {}
manager: kube-controller-manager
operation: Update
time: "2021-05-26T14:05:19Z"
name: web
namespace: default
resourceVersion: "92795"
selfLink: /apis/apps/v1/namespaces/default/deployments/web
uid: f7d3da76-4493-4288-b3a8-ef724c0a739c
spec:
progressDeadlineSeconds: 600
replicas: 2
revisionHistoryLimit: 10
selector:
matchLabels:
app: web
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx:1.14
imagePullPolicy: Always
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2021-05-26T14:05:19Z"
lastUpdateTime: "2021-05-26T14:05:19Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2021-05-26T14:05:03Z"
lastUpdateTime: "2021-05-26T14:05:19Z"
message: ReplicaSet "web-5dcb957ccc" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
使用这个资源编排文件生成应用 web
[root@k8smaster ~]# kubectl apply -f web.yaml
[root@k8smaster ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web-66bf4959f5-kfktx 1/1 Running 0 76s
web-66bf4959f5-mflm9 1/1 Running 0 76s
# 滚动升级到1.15
[root@k8smaster ~]# kubectl set image deploy web nginx=nginx:1.15
# 查看升级状态
[root@k8smaster ~]# kubectl rollout status deploy web
deployment "web" successfully rolled out
# 查看版本历史
[root@k8smaster ~]# kubectl rollout history deploy web
deployment.apps/web
REVISION CHANGE-CAUSE
1 <none>
2 <none>
# 回滚到上一个版本
[root@k8smaster ~]# kubectl rollout undo deploy web
deployment.apps/web rolled back
# 回滚到指定版本
[root@k8smaster ~]# kubectl rollout undo deploy web --to-revision=2
deployment.apps/web rolled back
二 动态扩缩容
# 当前pod副本
[root@k8smaster ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web-bbcf684cb-7g6mk 1/1 Running 0 51s
web-bbcf684cb-rsdv4 1/1 Running 0 65s
# 扩展副本10
[root@k8smaster ~]# kubectl scale deploy web --replicas=10
deployment.apps/web scaled
# 查看
[root@k8smaster ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web-bbcf684cb-29fkb 1/1 Running 0 36s
web-bbcf684cb-6kj7n 1/1 Running 0 36s
web-bbcf684cb-7g6mk 1/1 Running 0 2m4s
web-bbcf684cb-bt7xd 0/1 ContainerCreating 0 36s
web-bbcf684cb-d9b2v 0/1 ContainerCreating 0 35s
web-bbcf684cb-hjx5c 0/1 ContainerCreating 0 36s
web-bbcf684cb-hlkqw 0/1 ContainerCreating 0 35s
web-bbcf684cb-rsdv4 1/1 Running 0 2m18s
web-bbcf684cb-tj4f9 0/1 ContainerCreating 0 35s
web-bbcf684cb-wcrzq 0/1 ContainerCreating 0 36s
还没有评论,来说两句吧...