關於PaaS平臺集成解決方案,做者側重F5與PaaS(K8S爲例)集成的方案,將從管理平面的高可用安全、應用自動發佈、藍綠髮布、可視化4點論述。本文詳細闡述了觀點之一,即應用自動發佈。
前端
晏順
F5解決方案顧問node
擁有十多年運營商和金融行業從業經驗,2012年加入F5。 熟悉運營商核心網和金融信息系統架構,專一於客戶總體架構設計和應用的快速靈捷的交付。主要研究方向爲雲計算,容器及DevOps。涵蓋多雲環境下資源的彈性擴展,應用交付的自動化部署,運維自動化;以及雲環境中安全高可用架構的實現。具備豐富的數據中心架構設計以及自動化平臺對接經驗,完成了多家互聯網金融企業自動化運維平臺的對接上線。
Kubernetes設計角度靈活的利於了clusterip實現了集羣內部的服務互訪,然而針對面向互聯網的應用,須要實現基於集羣外部的發佈。知足DevOps的趨勢,須要實現k8s環境下應用的自動發佈。
Container Connector包含f5-k8s-controller和用戶定義的「F5資源」。f5-k8s-controller是一個能夠在Kubernetes Pod中運行的Docker容器。
「F5資源」是Kubernetes ConfigMap資源,它將編碼數據傳遞給f5-k8s-controller。這些資源告訴f5-k8s-controller:
1.在BIG-IP上配置哪些對象;
2.BIG-IP對象所屬的Kubernetes服務(分別是ConfigMap中的前端和後端屬性)。
f5-k8s-controller監視Kubernetes中F5資源的建立和修改。當它發現更改時,它會相應地修改BIG-IP。例如,對於F5 virtualServer資源,CC-Kubernetes執行如下操做:json
下面將演示經過F5 CC(Container Connector)與F5 BIG-IP聯動實現業務自動的對外發布。後端
0一、在BIG-IP設備上建立新的partition,命名爲kubernetes;
api
02建立serviceaccount;
kubectl create serviceaccount bigip-ctlr -n kube-system瀏覽器
03建立RBAC policy f5-k8s-sample-rbac.yaml,並apply;安全
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: bigip-ctlr-clusterrole
rules:
- apiGroups:
- ""
- "extensions"
resources:
- nodes
- services
- endpoints
- namespaces
- ingresses
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- ""
- "extensions"
resources:
- configmaps
- events
- ingresses/status
verbs:
- get
- list
- watch
- update
- create
- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: bigip-ctlr-clusterrole-binding
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: bigip-ctlr-clusterrole
subjects:
- kind: ServiceAccount
name: bigip-ctlr
namespace: kube-system架構
kubectl create -f f5-k8s-sample-rbac.yaml。app
04建立secrect保存admin用戶和密碼;
kubectl create secret generic bigip-login --namespace kube-system --from-literal=username=admin --from-literal=password=admin運維
05建立f5-cc-deployment.yaml,並apply;
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: k8s-bigip-ctlr-deployment
namespace: kube-system
spec:
replicas: 1
template:
kubectl create -f f5-cc-deployment.yaml。
建立完成後經過kubectlget pod -n kube-system | grep bigip命令確認CC狀態。
kubectl get pod -n kube-system | grep bigip
k8s-bigip-ctlr-deployment-66977b7bc6-x9rbf 1/1 Running 0 41m
使用命令kubectl logs k8s-bigip-ctlr-deployment-66977b7bc6-x9rbf -n kube-system確認CC處於監聽狀態。
kubectl logs k8s-bigip-ctlr-deployment-66977b7bc6-x9rbf -n kube-system
2019/04/29 07:18:46 [INFO] Starting: Version: v1.7.1, BuildInfo: n1279-465125010
2019/04/29 07:18:46 [INFO] ConfigWriter started: 0xc000445a10
2019/04/29 07:18:46 [INFO] Started config driver sub-process at pid: 12
2019/04/29 07:18:46 [INFO] NodePoller (0xc0003b4900) registering new listener: 0x1829650
2019/04/29 07:18:46 [INFO] NodePoller started: (0xc0003b4900)
2019/04/29 07:18:46 [INFO] Watching ConfigMap resources.
2019/04/29 07:18:46 [INFO] Handling ConfigMap resource events.
2019/04/29 07:18:46 [INFO] Registered BigIP Metrics
2019/04/29 07:18:46 [INFO] Wrote 0 Virtual Server and 0 IApp configs
2019/04/29 07:18:47 [INFO] [2019-04-29 07:18:47,333 __main__ INFO] entering inotify loop to watch /tmp/k8s-bigip-ctlr.config215984094/config.json
在k8s上建立應用,共包含三個yaml文件my-frontend-deployment.yaml,my-frontend-configmap.yaml,my-frontend-service.yaml;
my-frontend-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-frontend
spec:
replicas: 2
template:
metadata:
labels:
run: my-frontend
spec:
containers:
- image: "chen23/f5-demo-app"
env:
- name: F5DEMO_APP
value: "frontend"
- name: F5DEMO_BACKEND_URL
value: "http://my-backend/"
imagePullPolicy: IfNotPresent
name: my-frontend
ports:
- containerPort: 80
protocol: TCP
my-frontend-configmap.yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: my-frontend
namespace: default
labels:
f5type: virtual-server
data:
schema: "f5schemadb://bigip-virtual-server_v0.1.7.json"
data: |-
{
"virtualServer": {
"frontend": {
"balance": "round-robin",
"mode": "http",
"partition": "kubernetes",
"virtualAddress": {
"bindAddr": "10.1.10.81",
"port": 80
}
},
"backend": {
"serviceName": "my-frontend",
"servicePort": 80,
"healthMonitors": [{
"interval": 30,
"protocol": "http",
"send": "HEAD / HTTP/1.0\r\n\r\n",
"timeout": 91
}]
}
}
}
my-frontend-service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-frontend
labels:
run: my-frontend
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
type: NodePort
selector:
run: my-frontend
kubectl create -f my-frontend-deployment.yaml
kubectl create -f my-frontend-configmap.yaml
kubectl create -f my-frontend-service.yaml。
建立完成後查看service,該服務監聽在31752端口。
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 125d
my-frontend NodePort 10.109.185.196 <none> 80:31752/TCP 47m
07檢查BIG-IP上配置,workernode 10.1.1.175的端口31752自動添加到BIG-IP配置中。
經過瀏覽器訪問能夠打開頁面: