蓝绿部署
您可以在这里找到蓝绿部署的描述和历史。
确保您在正确的命名空间中
kubectl config set-context --current --namespace=myspace
确保没有其他资源部署:
kubectl get all
No resources found in myspace namespace.
部署 myboot 的 V1 版本:
kubectl apply -f apps/kubefiles/myboot-deployment-resources-limits.yml
缩放到 2 个副本:
kubectl scale deployment/myboot --replicas=2
监视并 show-labels:
watch kubectl get pods --show-labels
部署服务:
kubectl apply -f apps/kubefiles/myboot-service.yml
IP=$(minikube ip -p devnation)
PORT=$(kubectl get service/myboot -o jsonpath="{.spec.ports[*].nodePort}")
如果使用托管的 Kubernetes 集群(如 OpenShift),则使用 curl 和 EXTERNAL-IP 地址和端口 8080 或使用 kubectl 获取:
IP=$(kubectl get service myboot -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
PORT=$(kubectl get service myboot -o jsonpath="{.spec.ports[*].port}")
|
如果是在 AWS 上,则需要获取 |
IP=$(kubectl get service myboot -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
Curl 服务:
curl $IP:$PORT
并运行循环脚本:
while true
do curl $IP:$PORT
sleep 0.8
done
部署 myboot 的 V2 版本:
kubectl apply -f apps/kubefiles/myboot-deployment-resources-limits-v2.yml
验证新 pod/deployment 是否携带新代码:
PODNAME=$(kubectl get pod -l app=myboot-next -o name)
kubectl exec -it $PODNAME -- curl localhost:8080
Bonjour from Spring Boot! 1 on myboot-next-66b68c6659-ftcjr
现在更新单个服务以指向新 pod 并变为绿色:
kubectl patch svc/myboot -p '{"spec":{"selector":{"app":"myboot-next"}}}'
Aloha from Spring Boot! 240 on myboot-d78fb6d58-929wn
Bonjour from Spring Boot! 2 on myboot-next-66b68c6659-ftcjr
Bonjour from Spring Boot! 3 on myboot-next-66b68c6659-ftcjr
Bonjour from Spring Boot! 4 on myboot-next-66b68c6659-ftcjr
确定您更喜欢夏威夷(蓝色)而不是法语(绿色)并回退:
现在更新单个服务以指向新 pod 并变为蓝色:
kubectl patch svc/myboot -p '{"spec":{"selector":{"app":"myboot"}}}'
Bonjour from Spring Boot! 17 on myboot-next-66b68c6659-ftcjr
Aloha from Spring Boot! 257 on myboot-d78fb6d58-vqvlb
Aloha from Spring Boot! 258 on myboot-d78fb6d58-vqvlb