F5实现k8s环境下应用蓝绿发布

容器环境下灰度发布会是业务发布的常态,容器平台的特点也给灰度发布提供了条件。以下讲通过k8s中的F5 CC插件与BIGIP联动实现应用的蓝绿发布。

前一篇文章已经部署好了CC与BIGIP联动,下面通过node-blue.yaml和node-green.yaml实现两个版本的业务发布。
  1. 部署蓝绿两个版本的应用:

    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:

  • port: 80
    protocol: TCP
    targetPort: 80
    type: NodePort
    selector:
    run: node-blue

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:

  • port: 80
    protocol: TCP
    targetPort: 80
    type: NodePort
    selector:
    run: node-green

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

  1. 通过ingress发布应用,CC将自动发现配置并注入到BIGIP中

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:

  • host: blue.f5demo.com
    http:
    paths:
    • backend:
      serviceName: node-blue
      servicePort: 80
  • host: green.f5demo.com
    http:
    paths:
    • backend:
      serviceName: node-green
      servicePort: 80

kubectl create -f blue-green-ingress.yaml

部署完成后用kubectl查看ingress状态,通过BIGIP界面查看F5配置。

F5实现k8s环境下应用蓝绿发布_第1张图片

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文件中的定义,自动生成了转发策略:

F5实现k8s环境下应用蓝绿发布_第2张图片

  1. 更改测试机的/etc/hosts文件,将blue.f5demo.com和green.f5demo.com都指向BIGIP上的VIP地址。

10.1.10.82 blue.f5demo.com
10.1.10.82 green.f5demo.com

  1. 通过客户端访问测试,当输入blue.f5demo.com地址时出现页面:

F5实现k8s环境下应用蓝绿发布_第3张图片

当输入green.f5demo.com地址时出现页面:

F5实现k8s环境下应用蓝绿发布_第4张图片

通过F5 CC插件和BIGIP联动,可以实现业务的蓝绿发布。

你可能感兴趣的:(F5实现k8s环境下应用蓝绿发布)