關於PaaS平臺集成解決方案,做者側重F5與PaaS(K8S爲例)集成的方案,將從管理平面的高可用安全、應用自動發佈、藍綠髮布、可視化4點論述。本文詳細闡述了觀點之一,即應用藍綠髮布。node
晏順
F5解決方案顧問web
擁有十多年運營商和金融行業從業經驗,2012年加入F5。熟悉運營商核心網和金融信息系統架構,專一於客戶總體架構設計和應用的快速靈捷的交付。主要研究方向爲雲計算,容器及DevOps。涵蓋多雲環境下資源的彈性擴展,應用交付的自動化部署,運維自動化;以及雲環境中安全高可用架構的實現。具備豐富的數據中心架構設計以及自動化平臺對接經驗,完成了多家互聯網金融企業自動化運維平臺的對接上線。api
容器環境下灰度發佈會是業務發佈的常態,容器平臺的特色也給灰度發佈提供了條件。如下講經過k8s中的F5 CC插件與BIG-IP聯動實現應用的藍綠髮布。安全
前一篇文章已經部署好了CC與BIG-IP聯動,下面經過node-blue.yaml和node-green.yaml實現兩個版本的業務發佈。架構
1、部署藍綠兩個版本的應用:app
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-greenfrontend
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雲計算
2、經過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文件中的定義,自動生成了轉發策略:
3、更改測試機的/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
4、經過客戶端訪問測試,當輸入blue.f5demo.com地址時出現頁面:
當輸入green.f5demo.com地址時出現頁面:
經過F5 CC插件和BIG-IP聯動,能夠實現業務的藍綠髮布。