企业门户网站费用,做网站功能,选网站建设要注意什么,百度wordpress结构化数据插件 sign 检测失败K8S之常见部署方案 一、普通部署二、滚动更新#xff08;Rolling update#xff09;三、蓝绿部署#xff08;Blue/Green Deployment#xff09;四、灰度发布#xff08;金丝雀发布#xff09; 常见的部署方案参考博文#xff1a;常见部署方案#xff1a;普通部署、滚动… K8S之常见部署方案 一、普通部署二、滚动更新Rolling update三、蓝绿部署Blue/Green Deployment四、灰度发布金丝雀发布 常见的部署方案参考博文常见部署方案普通部署、滚动部署、蓝绿部署、灰度发布金丝雀发布 一、普通部署
特点 先停止旧的pod然后再创建新的pod这个过程服务是会间断的。
创建recreate.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: recreate
spec:strategy:type: Recreateselector:matchLabels:app: recreatereplicas: 4template:metadata:labels:app: recreatespec:containers:- name: recreateimage: registry.cn-hangzhou.aliyuncs.com/itcrazy2016/test-docker-image:v1.0ports:- containerPort: 8080livenessProbe:tcpSocket:port: 8080命令
kubectl apply -f recreate.yaml
kubectl get pods修改recreate.yaml文件
kubectl apply -f recreate.yaml
kubectl get podsconclusion 发现pod是先停止然后再创建新的。
NAME READY STATUS RESTARTS AGE
recreate-655d4868d8-5dqcz 0/1 Terminating 0 2m31s
recreate-655d4868d8-sb688 0/1 Terminating 0 2m31s测试
kubectl rollout pause deploy rollingupdate
kubectl rollout resume deploy rollingupdate
kubectl rollout undo deploy rollingupdate # 回到上一个版本二、滚动更新Rolling update
服务不会停止但是整个pod会有新旧并存的情况。
创建rollingupdate.yaml maxSurge 滚动升级时先启动的pod数量 maxUnavailable 滚动升级时允许的最大unavailable的pod数量 apiVersion: apps/v1
kind: Deployment
metadata:name: rollingupdate
spec:strategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdateselector:matchLabels:app: rollingupdatereplicas: 4template:metadata:labels:app: rollingupdatespec:containers:- name: rollingupdateimage: registry.cn-hangzhou.aliyuncs.com/itcrazy2016/test-docker-image:v1.0ports:- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:name: rollingupdate
spec:ports:- port: 80protocol: TCPtargetPort: 8080selector:app: rollingupdatetype: ClusterIP命令
kubectl apply -f rollingupdate.yaml
kubectl get pods
kubectl get svc
curl cluster-ip/dockerfile修改rollingupdate.yaml文件将镜像修改成v2.0
# 在w1上不断地访问观察输出
while sleep 0.2;do curl cluster-ip/dockerfile;echo ;done
# 在w2上监控pod
kubectl get pods -w
# 使得更改生效
kubectl apply -f rollingupdate.yaml
kubectl get podsconclusion 发现新旧pod是会共存的并且可以访问测试看一下
kubectl get pods -w
kubectl get svc可以发现新老版本的确会共存。 三、蓝绿部署Blue/Green Deployment 无需停机风险较小 1部署v1的应用一开始的状态 所有外部请求的流量都打到这个版本上2部署版本2的应用 版本2的代码与版本1不同(新功能、Bug修复等).3将流量从版本1切换到版本2。4如版本2测试正常就删除版本1正在使用的资源例如实例从此正式用版本2 创建bluegreen.yaml
#deploy
apiVersion: apps/v1
kind: Deployment
metadata:name: blue
spec:strategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdateselector:matchLabels:app: bluegreenreplicas: 4template:metadata:labels:app: bluegreenversion: v1.0spec:containers:- name: bluegreenimage: registry.cn-hangzhou.aliyuncs.com/itcrazy2016/test-docker-image:v1.0ports:- containerPort: 8080命令
kubectl apply -f bluegreen.yaml
kubectl get pods创建bluegreen-service.yaml
apiVersion: v1
kind: Service
metadata:name: bluegreen
spec:ports:- port: 80protocol: TCPtargetPort: 8080selector:app: bluegreenversion: v1.0type: ClusterIP命令
kubectl apply -f bluegreen-service.yaml
kubectl get svc
# 在w1上不断访问观察
while sleep 0.3;do curl cluster-ip/dockerfile;echo ;done修改bluegreen.yaml 01-deployment-name:blue — green 02-image:v1.0— v2.0 03-version:v1.0 — v2.0 kubectl apply -f bluegreen.yaml
kubectl get pods
# 同时观察刚才访问的地址有没有变化
# 可以发现两个版本就共存了并且之前访问的地址没有变化修改bluegreen-service.yaml
# 也就是把流量切到2.0的版本中
selector:app: bluegreenversion: v2.0kubectl apply -f bluegreen-service.yaml
kubectl get svc
# 同时观察刚才访问的地址有没有变化
# 发现流量已经完全切到了v2.0的版本上四、灰度发布金丝雀发布
修改bluegreen-service.yaml
selector:
app: bluegreen
version: v2.0 # 把version删除掉只是根据bluegreen进行选择修改后
apiVersion: v1
kind: Service
metadata:name: bluegreen
spec:ports:- port: 80protocol: TCPtargetPort: 8080selector:app: bluegreen#version: v1.0type: ClusterIP命令
kubectl apply -f bluegreen-service.yaml同时观察刚才访问的地址有没有变化发现此时新旧版本能够同时被访问到。