尝试使用Kubernetes的RollingUpdate/Rollback功能时,会感到非常兴奋和惊叹
你好,我是Class Act基础设施业务部的大塚。
我打算利用GKE环境来实际尝试Kubernetes的滚动更新和回滚。
验证方法
以下是验证流程的示意图:
首先,在GKE环境中创建Dockerfile和index.html文件,然后创建用于验证的Docker镜像。
将创建的镜像推送到Google Container Registry(类似于Docker Hub)。
准备用于Deployment和LoadBalancer的yaml文件,然后根据这些文件在GKE环境中部署。
使用Firefox连接到Deployment并确认index.html文件的内容。
然后修改index.html的内容,再次创建并推送镜像。
修改yaml文件并更新Deployment。更新成功后,使用Firefox确认index.html文件的内容已更新。
重复以上流程2-3次。
使用的术语
Dockerfile – Docker文件
Docker 可以从 Dockerfile 中读取指令并自动构建镜像。 Dockerfile 是一个文本文件,包含了构建镜像所需执行的命令行指令。
构建Docker镜像的命令 – docker build
执行docker build时,会自动化执行一系列命令行指令,并获得构建结果作为镜像。
谷歌容器注册表(Google Container Registry)
在容器注册表中,可以保存、管理和保护Docker容器镜像。通过容器注册表,可以进行统一的Docker镜像管理和漏洞分析。此外,通过细粒度的访问控制,可以决定允许哪个用户访问何种资源。
使用kubectl apply命令
通过使用apply命令,可以通过定义Kubernetes资源的文件来管理应用程序。运行kubectl apply命令可以创建和更新集群内的资源。这是管理Kubernetes应用程序的推荐方法,尤其适用于生产环境中。
我觉得以下关于使用kubectl create和kubectl apply时的图形界面是很直观易懂的。
可能是因为只有使用kubectl apply才能用kubectl diff命令清晰地显示出差异吧。大概吧。
我认为基本上是应该使用apply才是正确的。
环境
我正在使用GKE的自动驾驶功能来自动构建k8s集群。
该集群已由两个节点进行集群化。
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
gk3-my-k8s-cluster-default-pool-13c33173-fjcl Ready <none> 15m v1.25.7-gke.1000 10.128.0.6 34.31.37.35 Container-Optimized OS from Google 5.15.65+ containerd://1.6.18
gk3-my-k8s-cluster-default-pool-dda5f4e0-zrgs Ready <none> 15m v1.25.7-gke.1000 10.128.0.7 35.188.98.215 Container-Optimized OS from Google 5.15.65+ containerd://1.6.18
使用Dockerfile创建镜像并推送到GCR(第一次)。
首先准备了以下的html文件。
将这个文件与Dockerfile一起使用,构建成Docker镜像,但在升级版本时,会逐渐更改部分”ver1.0!”。
<h1>Hello GKE!</h1>
<h2>This is apache2 pod ver1.0!</h2>
Dockerfile中需要准备以下内容:
假设我写了“使用httpd的Docker镜像,在该镜像中使用位于GKE上的index.html文件!”这样的东西。
FROM httpd
COPY index.html /usr/local/apache2/htdocs/
请将其转换为镜像格式。考虑到推送到GCR上的便利性,请注意命名镜像的方式。
请确认并调整各个人的项目ID,该ID位于”gcr.io/”之后的部分。
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ docker build -t gcr.io/western-antonym-●●●●●●/apache2:1.0 .
请确保GKE后续可以识别到GCR。
(可能不需要这部分内容)
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ gcloud auth configure-docker
WARNING: Your config file at [/home/ohtsuka_honban/.docker/config.json] contains these credential helper entries:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud"
}
}
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
gcloud credential helpers already registered correctly.
将在GCR上创建的图像推送。
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ docker push gcr.io/western-antonym-●●●●●●/apache2:1.0
The push refers to repository [gcr.io/western-antonym-●●●●●●/apache2]
90003dd9562f: Pushed
76554aaac635: Layer already exists
12ef76c76336: Layer already exists
ce0966b9747d: Layer already exists
1f1fd2176485: Layer already exists
8553b91047da: Layer already exists
1.0: digest: sha256:e4ec01a71471dec8ebbe0dc65372b715142c5dd4b9640f0a3df0d3fbf071ac36 size: 1573
使用GKE部署Deployment和LoadBalancer,并通过Web浏览器检查index.html文件(第一次)。
部署所需的yaml文件如下:
strategy部分与滚动更新或回滚相关。
本次选择了”rollingUpdate”策略,但似乎还有一种名为”Recreate”的策略。如果不指定任何策略,系统会自动选择”rollingUpdate”,但为了学习目的,我们进行了输入。
“maxSurge: 1″的意思是指定可以创建超过声明的Pod数量的Pod数为1,而”maxUnavailable: 0″的意思是指定处于停止状态的最大Pod数为0。
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache2-deployment
labels:
name: apache2-deployment
spec:
replicas: 2
selector:
matchLabels:
name: apache2
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
name: apache2
spec:
containers:
- name: apache2-con
image: gcr.io/western-antonym-●●●●●●/apache2:1.0
ports:
- containerPort: 80
由于对”maxSurge: 1″和”maxUnavailable: 0″一直不太理解,所以我自己动手搜索了一下,并找到了一篇很容易理解的文章。
大致上来说
-
- “yamlで指定されたreplicasの数”+”yamlで指定されたmaxSurgeの数”=”ローリングアップデート/ロールバック時の最大のpodの数”(私の場合、2 + 1 = 3)
- “yaml指定されたreplicasの数”+”yamlで指定されたmaxUnavailableの数”=”ローリングアップデート/ロールバック時の最小のpodの数”(私の場合、2 – 0 = 2)
我认为它意味着给Kubernetes发送指令,要求在滚动更新/回滚时保持pod数量在2到3之间。
我們將進行部署。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl apply -f apache2-deployment.yaml
Warning: Autopilot set default resource requests for Deployment default/apache2-deployment, as resource requests were not specified. See http://g.co/gke/autopilot-defaults
deployment.apps/apache2-deployment created
我們來確認一下結果。你可以看到已經創建了兩個Pod。同時,也創建了Deployment以及相應的Replicaset。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl get all -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/apache2-deployment-7868df7b76-d8tnd 1/1 Running 0 37s 10.109.128.138 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
pod/apache2-deployment-7868df7b76-jbmbq 1/1 Running 0 37s 10.109.128.139 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 94m <none>
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/apache2-deployment 2/2 2 2 37s apache2-con gcr.io/western-antonym-386513/apache2:1.0 name=apache2
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/apache2-deployment-7868df7b76 2 2 2 38s apache2-con gcr.io/western-antonym-386513/apache2:1.0 name=apache2,pod-template-hash=7868df7b76
部署负载均衡器。
我们准备的YAML文件如下。
apiVersion: v1
kind: Service
metadata:
name: apache2-loadbalancer
spec:
type: LoadBalancer
selector:
name: apache2
ports:
- protocol: TCP
port: 60080
targetPort: 80
我们将进行部署。结果看起来也没有问题。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl apply -f apache2-loadbalancer.yaml
service/apache2-loadbalancer created
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
apache2-loadbalancer LoadBalancer 10.110.0.162 35.238.40.41 60080:30377/TCP 43s name=apache2
kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 95m <none>
使用Dockerfile创建镜像并推送到GCR(第二次)。
基于将index.html中的”ver1.0!”更改为”ver1.1!”的内容创建一个名为”apache2:1.1″的Docker镜像,并将其推送到GCR。
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ cat index.html
<h1>Hello GKE!</h1>
<h2>This is apache2 pod ver1.1!</h2>
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ docker build -t gcr.io/western-antonym-●●●●●●/apache2:1.1 .
ohtsuka_honban@cloudshell:~/yaml/docker (western-antonym-●●●●●●)$ docker push gcr.io/western-antonym-●●●●●●/apache2:1.1
在GKE上部署 Deployment 和 LoadBalancer,通过Web浏览器检查 index.html(第二次)。
我将准备一个用于滚动更新的YAML文件。除了更新pod使用的镜像外,其他内容都没有变化。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ cp -p apache2-deployment.yaml apache2-deployment-1.1.yaml
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ diff apache2-deployment.yaml apache2-deployment-1.1.yaml
23c23
< image: gcr.io/western-antonym-386513/apache2:1.0
---
> image: gcr.io/western-antonym-386513/apache2:1.1
使用kubectl apply命令对Deployment进行更新。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl apply -f apache2-deployment-1.1.yaml
deployment.apps/apache2-deployment configured
使用`watch`命令实时追踪`kubectl get all -o wide`的输出结果。
滚动更新过程中的输出结果如下:
创建了一个以”apache2:1.1″镜像为基础的Replicaset,其名称为”apache2-deployment-67f8d54489″,在该Replicaset内有一个被管理的pod,名称为”apache2-deployment-67f8d54489-dt997″,它正在开始创建过程。
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/apache2-deployment-67f8d54489-dt997 0/1 Pending 0 8s <none> <none> <none> <none>
pod/apache2-deployment-7868df7b76-d8tnd 1/1 Running 0 10m 10.109.128.138 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
pod/apache2-deployment-7868df7b76-jbmbq 1/1 Running 0 10m 10.109.128.139 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/apache2-loadbalancer LoadBalancer 10.110.0.162 35.238.40.41 60080:30377/TCP 9m32s name=apache2
service/kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 104m <none>
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/apache2-deployment 2/2 1 2 10m apache2-con gcr.io/western-antonym-386513/apache2:1.1 name=apache2
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/apache2-deployment-67f8d54489 1 1 0 9s apache2-con gcr.io/western-antonym-386513/apache2:1.1 name=apache2,pod-template-hash=67f8d54489
replicaset.apps/apache2-deployment-7868df7b76 2 2 2 10m apache2-con gcr.io/western-antonym-386513/apache2:1.0 name=apache2,pod-template-hash=7868df7b76
最终状态如下:ver1.0的pod已被删除,只有1.1的pod在运行。
我个人认为令人意外的是ver1.0的replicaset仍然存在。可能是为了在回滚时内部查看配置值而保留的,不知道是怎么回事。。。?
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/apache2-deployment-67f8d54489-4hzkj 1/1 Running 0 68s 10.109.128.141 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
pod/apache2-deployment-67f8d54489-v6nnw 1/1 Running 0 68s 10.109.128.142 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/apache2-loadbalancer LoadBalancer 10.110.0.162 35.238.40.41 60080:30377/TCP 13m name=apache2
service/kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 108m <none>
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/apache2-deployment 2/2 2 2 14m apache2-con gcr.io/western-antonym-386513/apache2:1.1 name=apache2
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/apache2-deployment-67f8d54489 2 2 2 4m24s apache2-con gcr.io/western-antonym-386513/apache2:1.1 name=apache2,pod-template-hash=67f8d54489
replicaset.apps/apache2-deployment-7868df7b76 0 0 0 14m apache2-con gcr.io/western-antonym-386513/apache2:1.0 name=apache2,pod-template-hash=7868df7b76
我尝试使用 kubectl rollout status 进行确认。它写着无问题地完成了滚动更新。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl rollout status deployment
deployment "apache2-deployment" successfully rolled out
我也会查看kubectl rollout history命令。
看起来过去的记录被作为REVISION进行管理。
REVISION 1是ver1.0的内容。REVISION 2是ver1.1的内容。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl rollout history deployment
deployment.apps/apache2-deployment
REVISION CHANGE-CAUSE
1 <none>
2 <none>
我会尝试使用kubectl diff命令进行查看。
通过使用-f选项指定yaml文件,可以看到它会输出该yaml文件与当前正在运行的Deployment之间的差异。
实际上,即使对apache2-deployment-1.1.yaml(当前正在运行的)进行diff操作,也没有任何输出。
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl diff -f apache2-deployment.yaml
diff -u -N /tmp/LIVE-4004392298/apps.v1.Deployment.default.apache2-deployment /tmp/MERGED-3784003542/apps.v1.Deployment.default.apache2-deployment
--- /tmp/LIVE-4004392298/apps.v1.Deployment.default.apache2-deployment 2023-05-12 23:45:16.669876027 +0000
+++ /tmp/MERGED-3784003542/apps.v1.Deployment.default.apache2-deployment 2023-05-12 23:45:16.670876121 +0000
@@ -7,7 +7,7 @@
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"name":"apache2-deployment"},"name":"apache2-deployment","namespace":"default"},"spec":{"replicas":2,"selector":{"matchLabels":{"name":"apache2"}},"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0}},"template":{"metadata":{"labels":{"name":"apache2"}},"spec":{"containers":[{"image":"gcr.io/western-antonym-●●●●●●/apache2:1.1","name":"apache2-con","ports":[{"containerPort":80}]}]}}}}
creationTimestamp: "2023-05-12T23:25:59Z"
- generation: 2
+ generation: 3
labels:
name: apache2-deployment
name: apache2-deployment
@@ -33,7 +33,7 @@
name: apache2
spec:
containers:
- - image: gcr.io/western-antonym-●●●●●●/apache2:1.1
+ - image: gcr.io/western-antonym-●●●●●●/apache2:1.0
imagePullPolicy: IfNotPresent
name: apache2-con
ports:
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$ kubectl diff -f apache2-deployment-1.1.yaml
ohtsuka_honban@cloudshell:~/yaml (western-antonym-●●●●●●)$
使用Dockerfile创建镜像并推送到GCR(第三次)。
抱歉,我们将更改HTML版本为1.2并创建图像,然后将其推送到GCR。
ohtsuka_honban@cloudshell:~/yaml/docker$ cat index.html
<h1>Hello GKE!</h1>
<h2>This is apache2 pod ver1.2!</h2>
ohtsuka_honban@cloudshell:~/yaml/docker$ docker build -t gcr.io/western-antonym-●●●●●●/apache2:1.2 .
ohtsuka_honban@cloudshell:~/yaml/docker$ docker push gcr.io/western-antonym-●●●●●●/apache2:1.2
在GKE上部署Deployment和LoadBalancer,并使用Web浏览器确认index.html(第三次)。
准备用于滚动更新的yaml文件,进行更新操作。
ohtsuka_honban@cloudshell:~/yaml$ cp -p apache2-deployment-1.1.yaml apache2-deployment-1.2.yaml
ohtsuka_honban@cloudshell:~/yaml$ vi apache2-deployment-1.2.yaml
ohtsuka_honban@cloudshell:~/yaml$ diff apache2-deployment-1.1.yaml apache2-deployment-1.2.yaml
23c23
< image: gcr.io/western-antonym-●●●●●●/apache2:1.1
---
> image: gcr.io/western-antonym-●●●●●●/apache2:1.2
ohtsuka_honban@cloudshell:~/yaml$ kubectl apply -f apache2-deployment-1.2.yaml
deployment.apps/apache2-deployment configured
有一个基于版本1.2的Replicaset叫做”apache2-deployment-8596d9c558″,同时也创建了该Replicaset下的pod叫做”apache2-deployment-8596d9c558-l6nqr”。
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/apache2-deployment-67f8d54489-4hzkj 1/1 Running 0 65m 10.109.128.141 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
pod/apache2-deployment-67f8d54489-v6nnw 1/1 Running 0 65m 10.109.128.142 gk3-my-k8s-cluster-pool-1-458925f9-kpcw <none> <none>
pod/apache2-deployment-8596d9c558-l6nqr 0/1 ContainerCreating 0 95s <none> gk3-my-k8s-cluster-pool-1-09501b89-mjg7 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/apache2-loadbalancer LoadBalancer 10.110.0.162 35.238.40.41 60080:30377/TCP 78m name=apache2
service/kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 173m <none>
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/apache2-deployment 2/2 1 2 79m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.2 name=apache2
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/apache2-deployment-67f8d54489 2 2 2 69m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.1 name=apache2,pod-template-hash=67f8d54489
replicaset.apps/apache2-deployment-7868df7b76 0 0 0 79m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.0 name=apache2,pod-template-hash=7868df7b76
replicaset.apps/apache2-deployment-8596d9c558 1 1 0 96s apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.2 name=apache2,pod-template-hash=8596d9c558
最终结果是下列所示。
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/apache2-deployment-8596d9c558-6hb4b 1/1 Running 0 15s 10.109.128.197 gk3-my-k8s-cluster-pool-1-09501b89-mjg7 <none> <none>
pod/apache2-deployment-8596d9c558-l6nqr 1/1 Running 0 2m14s 10.109.128.194 gk3-my-k8s-cluster-pool-1-09501b89-mjg7 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/apache2-loadbalancer LoadBalancer 10.110.0.162 35.238.40.41 60080:30377/TCP 79m name=apache2
service/kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 173m <none>
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/apache2-deployment 2/2 2 2 80m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.2 name=apache2
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/apache2-deployment-67f8d54489 0 0 0 69m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.1 name=apache2,pod-template-hash=67f8d54489
replicaset.apps/apache2-deployment-7868df7b76 0 0 0 80m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.0 name=apache2,pod-template-hash=7868df7b76
replicaset.apps/apache2-deployment-8596d9c558 2 2 2 2m15s apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.2 name=apache2,pod-template-hash=8596d9c558
让我们想象迁移。
我来看一下发布历史。看起来有一个修订版本增加了。
ohtsuka_honban@cloudshell:~/yaml$ kubectl rollout history deployment
deployment.apps/apache2-deployment
REVISION CHANGE-CAUSE
1 <none>
2 <none>
3 <none>
尝试进行回滚操作
听说可以使用kubectl rollout undo命令并指定REVISION来回滚到该REVISION的状态。我们将尝试实际操作。
这次我们将回滚到两个版本之前的REVISION 1,也就是ver1.0的状态。
ohtsuka_honban@cloudshell:~/yaml$ kubectl rollout undo deployment apache2-deployment --to-revision=1
deployment.apps/apache2-deployment rolled back
ohtsuka_honban@cloudshell:~/yaml$ kubectl rollout status deployment
Waiting for deployment "apache2-deployment" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "apache2-deployment" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "apache2-deployment" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "apache2-deployment" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "apache2-deployment" rollout to finish: 1 old replicas are pending termination...
deployment "apache2-deployment" successfully rolled out
回滚操作的结果如下。
你可以通过查看Replicas部分来更直观地理解,版本1.0的Replicas”apache2-deployment-7868df7b76″已经变为2了。
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/apache2-deployment-7868df7b76-4lxc5 1/1 Running 0 40s 10.109.128.200 gk3-my-k8s-cluster-pool-1-09501b89-mjg7 <none> <none>
pod/apache2-deployment-7868df7b76-f9cnf 1/1 Running 0 40s 10.109.128.199 gk3-my-k8s-cluster-pool-1-09501b89-mjg7 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/apache2-loadbalancer LoadBalancer 10.110.0.162 35.238.40.41 60080:30377/TCP 89m name=apache2
service/kubernetes ClusterIP 10.110.0.1 <none> 443/TCP 3h3m <none>
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/apache2-deployment 2/2 2 2 90m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.0 name=apache2
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/apache2-deployment-67f8d54489 0 0 0 79m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.1 name=apache2,pod-template-hash=67f8d54489
replicaset.apps/apache2-deployment-7868df7b76 2 2 2 90m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.0 name=apache2,pod-template-hash=7868df7b76
replicaset.apps/apache2-deployment-8596d9c558 0 0 0 12m apache2-con gcr.io/western-antonym-●●●●●●/apache2:1.2 name=apache2,pod-template-hash=8596d9c558
我会查看发布历史。
1已经消失,4已经创建。可能是因为GKE的设置决定了最多管理3个世代,所以这次回滚导致最旧的一代消失了。似乎还可以进行设置更改。虽然我没有尝试过。。。
ohtsuka_honban@cloudshell:~/yaml$ kubectl rollout history deployment
deployment.apps/apache2-deployment
REVISION CHANGE-CAUSE
2 <none>
3 <none>
4 <none>