一次成功后
kubectl rollout restart deployment/foo
这
kubectl rollout undo deployment/foo
或者
kubectl rollout undo deployment/foo --to-revision=x
没有效果。我的意思是,豆荚被新的豆荚取代,并创建了一个新的修订版,可以用
kubectl rollout history deployment foo
但是当我调用服务时,回滚没有效果。
我还尝试删除imagePullPolicy: Always,猜测即使在回滚时它也总是在拉动,但没有成功,因为可能一件事与另一件事无关。
imagePullPolicy: Always
编辑:测试很简单,我更改了http api的健康检查路由以在json中返回不同的东西,它没有。
为了能够回滚到以前的版本,不要忘记将 –record 参数附加到您的 kubectl 命令,例如:
kubectl apply -f DEPLOYMENT.yaml --record
然后你应该能够看到你所知道的历史:
kubectl rollout history deployment DEPLOYMENT_NAME
您的回滚将正常工作
kubectl rollout undo deployment DEPLOYMENT_NAME --to-revision=CHOOSEN_REVISION_NUMBER
小例子:
在这里考虑我的 nginx 部署清单“nginx-test.yaml”:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80
让我们创建它:
❯ kubectl apply -f nginx-test.yaml --record Flag --record has been deprecated, --record will be removed in the future deployment.apps/nginx-deployment created
让我们检查一下这个部署的镜像,正如清单中所预期的那样:
❯ k get pod nginx-deployment-74d589986c-k9whj -o yaml | grep image: - image: nginx image: docker.io/library/nginx:latest
现在让我们将此部署的映像修改为“nginx:1.21”:
#"nginx=" correspond to the name of the container inside the pod create by the deployment. ❯ kubectl set image deploy nginx-deployment nginx=nginx:1.21.6 deployment.apps/nginx-deployment image updated
我们可以选择检查推出状态:
❯ kubectl rollout status deployment nginx-deployment deployment "nginx-deployment" successfully rolled out
我们可以通过以下方式检查推出历史:
❯ kubectl rollout history deploy nginx-deployment deployment.apps/nginx-deployment REVISION CHANGE-CAUSE 1 kubectl apply --filename=nginx-test.yaml --record=true 2 kubectl apply --filename=nginx-test.yaml --record=true
让我们按预期检查此部署的映像:
❯ k get pod nginx-deployment-66dcfc79b5-4pk7w -o yaml | grep image: - image: nginx:1.21.6 image: docker.io/library/nginx:1.21.6
哦,不,我不喜欢这张照片!让我们回滚:
❯ kubectl rollout undo deployment nginx-deployment --to-revision=1 deployment.apps/nginx-deployment rolled back
创建:
> kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/nginx-deployment-66dcfc79b5-4pk7w 1/1 Running 0 3m41s 10.244.3.4 so-cluster-1-worker3 <none> <none> pod/nginx-deployment-74d589986c-m2htr 0/1 ContainerCreating 0 13s <none> so-cluster-1-worker2 <none> <none>
几秒钟后:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/nginx-deployment-74d589986c-m2htr 1/1 Running 0 23s 10.244.4.10 so-cluster-1-worker2 <none> <none>
如您所见,它有效:
❯ k get pod nginx-deployment-74d589986c-m2htr -o yaml | grep image: - image: nginx image: docker.io/library/nginx:latest
让我们重新检查历史:
您可以使用“kubernetes.io/change-cause”注释更改推出历史记录的 CHANGE-CAUSE:
❯ kubectl annotate deploy nginx-deployment kubernetes.io/change-cause="update image from 1.21.6 to latest" --reco rd Flag --record has been deprecated, --record will be removed in the future deployment.apps/nginx-deployment annotated
❯ kubectl rollout history deploy nginx-deployment deployment.apps/nginx-deployment REVISION CHANGE-CAUSE 2 kubectl apply --filename=nginx-test.yaml --record=true 3 update image from 1.21.6 to latest
让我们描述一下部署:
❯ kubectl describe deploy nginx-deploy Name: nginx-deployment Namespace: so-tests CreationTimestamp: Fri, 06 May 2022 00:56:09 -0300 Labels: app=nginx Annotations: deployment.kubernetes.io/revision: 3 kubernetes.io/change-cause: update image from latest to latest ...
希望这对你有所帮助,bgues。