kubenete滚动升级版本动态扩缩容

傷城~ 2022-10-16 07:13 273阅读 0赞

一 滚动升级

根据资源编排文件部署一个Nginx应用,指定其版本为1.14,副本数为2个,对其升级为1.15,这个资源描述文件可以生成,然后修改副本数和nginx版本

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. deployment.kubernetes.io/revision: "1"
  6. creationTimestamp: "2021-05-26T14:05:03Z"
  7. generation: 1
  8. labels:
  9. app: web
  10. managedFields:
  11. - apiVersion: apps/v1
  12. fieldsType: FieldsV1
  13. fieldsV1:
  14. f:metadata:
  15. f:labels:
  16. .: {}
  17. f:app: {}
  18. f:spec:
  19. f:progressDeadlineSeconds: {}
  20. f:replicas: {}
  21. f:revisionHistoryLimit: {}
  22. f:selector:
  23. f:matchLabels:
  24. .: {}
  25. f:app: {}
  26. f:strategy:
  27. f:rollingUpdate:
  28. .: {}
  29. f:maxSurge: {}
  30. f:maxUnavailable: {}
  31. f:type: {}
  32. f:template:
  33. f:metadata:
  34. f:labels:
  35. .: {}
  36. f:app: {}
  37. f:spec:
  38. f:containers:
  39. k:{"name":"nginx"}:
  40. .: {}
  41. f:image: {}
  42. f:imagePullPolicy: {}
  43. f:name: {}
  44. f:resources: {}
  45. f:terminationMessagePath: {}
  46. f:terminationMessagePolicy: {}
  47. f:dnsPolicy: {}
  48. f:restartPolicy: {}
  49. f:schedulerName: {}
  50. f:securityContext: {}
  51. f:terminationGracePeriodSeconds: {}
  52. manager: kubectl
  53. operation: Update
  54. time: "2021-05-26T14:05:03Z"
  55. - apiVersion: apps/v1
  56. fieldsType: FieldsV1
  57. fieldsV1:
  58. f:metadata:
  59. f:annotations:
  60. .: {}
  61. f:deployment.kubernetes.io/revision: {}
  62. f:status:
  63. f:availableReplicas: {}
  64. f:conditions:
  65. .: {}
  66. k:{"type":"Available"}:
  67. .: {}
  68. f:lastTransitionTime: {}
  69. f:lastUpdateTime: {}
  70. f:message: {}
  71. f:reason: {}
  72. f:status: {}
  73. f:type: {}
  74. k:{"type":"Progressing"}:
  75. .: {}
  76. f:lastTransitionTime: {}
  77. f:lastUpdateTime: {}
  78. f:message: {}
  79. f:reason: {}
  80. f:status: {}
  81. f:type: {}
  82. f:observedGeneration: {}
  83. f:readyReplicas: {}
  84. f:replicas: {}
  85. f:updatedReplicas: {}
  86. manager: kube-controller-manager
  87. operation: Update
  88. time: "2021-05-26T14:05:19Z"
  89. name: web
  90. namespace: default
  91. resourceVersion: "92795"
  92. selfLink: /apis/apps/v1/namespaces/default/deployments/web
  93. uid: f7d3da76-4493-4288-b3a8-ef724c0a739c
  94. spec:
  95. progressDeadlineSeconds: 600
  96. replicas: 2
  97. revisionHistoryLimit: 10
  98. selector:
  99. matchLabels:
  100. app: web
  101. strategy:
  102. rollingUpdate:
  103. maxSurge: 25%
  104. maxUnavailable: 25%
  105. type: RollingUpdate
  106. template:
  107. metadata:
  108. creationTimestamp: null
  109. labels:
  110. app: web
  111. spec:
  112. containers:
  113. - image: nginx:1.14
  114. imagePullPolicy: Always
  115. name: nginx
  116. resources: {}
  117. terminationMessagePath: /dev/termination-log
  118. terminationMessagePolicy: File
  119. dnsPolicy: ClusterFirst
  120. restartPolicy: Always
  121. schedulerName: default-scheduler
  122. securityContext: {}
  123. terminationGracePeriodSeconds: 30
  124. status:
  125. availableReplicas: 1
  126. conditions:
  127. - lastTransitionTime: "2021-05-26T14:05:19Z"
  128. lastUpdateTime: "2021-05-26T14:05:19Z"
  129. message: Deployment has minimum availability.
  130. reason: MinimumReplicasAvailable
  131. status: "True"
  132. type: Available
  133. - lastTransitionTime: "2021-05-26T14:05:03Z"
  134. lastUpdateTime: "2021-05-26T14:05:19Z"
  135. message: ReplicaSet "web-5dcb957ccc" has successfully progressed.
  136. reason: NewReplicaSetAvailable
  137. status: "True"
  138. type: Progressing
  139. observedGeneration: 1
  140. readyReplicas: 1
  141. replicas: 1
  142. updatedReplicas: 1

使用这个资源编排文件生成应用 web

  1. [root@k8smaster ~]# kubectl apply -f web.yaml
  2. [root@k8smaster ~]# kubectl get pods
  3. NAME READY STATUS RESTARTS AGE
  4. web-66bf4959f5-kfktx 1/1 Running 0 76s
  5. web-66bf4959f5-mflm9 1/1 Running 0 76s
  6. # 滚动升级到1.15
  7. [root@k8smaster ~]# kubectl set image deploy web nginx=nginx:1.15
  8. # 查看升级状态
  9. [root@k8smaster ~]# kubectl rollout status deploy web
  10. deployment "web" successfully rolled out
  11. # 查看版本历史
  12. [root@k8smaster ~]# kubectl rollout history deploy web
  13. deployment.apps/web
  14. REVISION CHANGE-CAUSE
  15. 1 <none>
  16. 2 <none>
  17. # 回滚到上一个版本
  18. [root@k8smaster ~]# kubectl rollout undo deploy web
  19. deployment.apps/web rolled back
  20. # 回滚到指定版本
  21. [root@k8smaster ~]# kubectl rollout undo deploy web --to-revision=2
  22. deployment.apps/web rolled back

二 动态扩缩容

  1. # 当前pod副本
  2. [root@k8smaster ~]# kubectl get pods
  3. NAME READY STATUS RESTARTS AGE
  4. web-bbcf684cb-7g6mk 1/1 Running 0 51s
  5. web-bbcf684cb-rsdv4 1/1 Running 0 65s
  6. # 扩展副本10
  7. [root@k8smaster ~]# kubectl scale deploy web --replicas=10
  8. deployment.apps/web scaled
  9. # 查看
  10. [root@k8smaster ~]# kubectl get pods
  11. NAME READY STATUS RESTARTS AGE
  12. web-bbcf684cb-29fkb 1/1 Running 0 36s
  13. web-bbcf684cb-6kj7n 1/1 Running 0 36s
  14. web-bbcf684cb-7g6mk 1/1 Running 0 2m4s
  15. web-bbcf684cb-bt7xd 0/1 ContainerCreating 0 36s
  16. web-bbcf684cb-d9b2v 0/1 ContainerCreating 0 35s
  17. web-bbcf684cb-hjx5c 0/1 ContainerCreating 0 36s
  18. web-bbcf684cb-hlkqw 0/1 ContainerCreating 0 35s
  19. web-bbcf684cb-rsdv4 1/1 Running 0 2m18s
  20. web-bbcf684cb-tj4f9 0/1 ContainerCreating 0 35s
  21. web-bbcf684cb-wcrzq 0/1 ContainerCreating 0 36s

发表评论

表情:
评论列表 (有 0 条评论,273人围观)

还没有评论,来说两句吧...

相关阅读