关于PaaS平台集成解决方案,作者侧重F5与PaaS(K8S为例)集成的方案,将从管理平面的高可用安全、应用自动发布、蓝绿发布、可视化4点论述。本文详细阐述了观点之一,即应用蓝绿发布。
晏顺
F5解决方案顾问
拥有十多年运营商和金融行业从业经验,2012年加入F5。熟悉运营商核心网和金融信息系统架构,专注于客户整体架构设计和应用的快速灵捷的交付。主要研究方向为云计算,容器及DevOps。涵盖多云环境下资源的弹性扩展,应用交付的自动化部署,运维自动化;以及云环境中安全高可用架构的实现。具有丰富的数据中心架构设计以及自动化平台对接经验,完成了多家互联网金融企业自动化运维平台的对接上线。
容器环境下灰度发布会是业务发布的常态,容器平台的特点也给灰度发布提供了条件。以下讲通过k8s中的F5 CC插件与BIG-IP联动实现应用的蓝绿发布。
前一篇文章已经部署好了CC与BIG-IP联动,下面通过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:
- 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
二、通过ingress发布应用,CC将自动发现配置并注入到BIG-IP中。
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状态,通过BIG-IP界面查看F5配置。
kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
blue-green-ingress blue.f5demo.com,green.f5demo.com 10.1.10.82 80 21m
BIG-IP上根据yaml文件中的定义,自动生成了转发策略:
三、更改测试机的/etc/hosts文件,将blue.f5demo.com和green.f5demo.com都指向BIG-IP上的VIP地址。
10.1.10.82 blue.f5demo.com
10.1.10.82 green.f5demo.com
四、通过客户端访问测试,当输入blue.f5demo.com地址时出现页面:
当输入green.f5demo.com地址时出现页面:
通过F5 CC插件和BIG-IP联动,可以实现业务的蓝绿发布。