容器环境下灰度发布会是业务发布的常态,容器平台的特点也给灰度发布提供了条件。以下讲通过k8s中的F5 CC插件与BIGIP联动实现应用的蓝绿发布。
前一篇文章已经部署好了CC与BIGIP联动,下面通过node-blue.yaml和node-green.yaml实现两个版本的业务发布。
部署蓝绿两个版本的应用:
node-blue.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: node-blue
spec:
replicas: 1
template:
metadata:
labels:
run: node-blue
spec:
containers:
- image: “chen23/f5-demo-app”
env:
- name: F5DEMO_APP
value: “website”
- name: F5DEMO_NODENAME
value: “Node Blue”
- name: F5DEMO_COLOR
value: 0000FF
imagePullPolicy: IfNotPresent
name: node-blue
ports:
- containerPort: 80
protocol: TCP
apiVersion: v1
kind: Service
metadata:
name: node-blue
labels:
run: node-blue
spec:
ports:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: node-green
spec:
replicas: 1
template:
metadata:
labels:
run: node-green
spec:
containers:
- image: “chen23/f5-demo-app”
env:
- name: F5DEMO_APP
value: “website”
- name: F5DEMO_NODENAME
value: “Node Green”
- name: F5DEMO_COLOR
value: 00FF00
imagePullPolicy: IfNotPresent
name: node-green
ports:
- containerPort: 80
protocol: TCP
apiVersion: v1
kind: Service
metadata:
name: node-green
labels:
run: node-green
spec:
ports:
kubectl create -f node-blue.yaml
kubectl create -f node-green.yaml
部署完成后通过kubectl命令查看deployment和service状态
kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
my-frontend 2/2 2 2 84m
node-blue 1/1 1 1 18m
node-green 1/1 1 1 18m
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 443/TCP 125d
my-frontend NodePort 10.109.185.196 80:31752/TCP 84m
node-blue NodePort 10.102.149.31 80:32215/TCP 18m
node-green NodePort 10.98.88.88 80:31038/TCP 18m
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: blue-green-ingress
annotations:
virtual-server.f5.com/ip: “10.1.10.82”
virtual-server.f5.com/http-port: “80”
virtual-server.f5.com/partition: “kubernetes”
virtual-server.f5.com/health: |
[
{
“path”: “blue.f5demo.com/”,
“send”: “HTTP GET /”,
“interval”: 5,
“timeout”: 15
}, {
“path”: “green.f5demo.com/”,
“send”: “HTTP GET /”,
“interval”: 5,
“timeout”: 15
}
]
kubernetes.io/ingress.class: “f5”
spec:
rules:
kubectl create -f blue-green-ingress.yaml
部署完成后用kubectl查看ingress状态,通过BIGIP界面查看F5配置。
kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
blue-green-ingress blue.f5demo.com,green.f5demo.com 10.1.10.82 80 21m
BIGIP上根据yaml文件中的定义,自动生成了转发策略:
10.1.10.82 blue.f5demo.com
10.1.10.82 green.f5demo.com
当输入green.f5demo.com地址时出现页面:
通过F5 CC插件和BIGIP联动,可以实现业务的蓝绿发布。