Openshift-F5集成(南北流量走F5)

使用F5与Openshift集成目的

外部流量访问应用时,通过F5 BIG-IP硬件设备直接代理到集群中的Pod。
这样做的好处,很明显。

  • 使用硬件负载均衡器替换掉软件负载均衡器,提高性能。
  • F5有更灵活的配置,可以实现更复杂的流量控制

Openshift操作

Openshift通过BIG-IP Controller来控制BIG-IP设备。由于Openshift是基于Kubernetes的,所以它们使用同一个Controller(k8s-bigip-ctlr)。BIG-IP Controller为集群中的应用配置BIG-IP对象,提供南北流量的服务。

F5集成Openshift原理图

BIG-IP Controller有两种方式来使用F5 BIG-IP设备

  • 为Openshift中的Service提供代理流量
  • 为Openshift中的Route提供代理流量

为Openshift中的Service提供代理流量(不介绍具体部署操作)

这种方式,我们测试下来发现,需要为对外提供服务的Service绑定到F5的不同端口,同时外部访问应用时需要指定端口号。如:
app1.openshift.example.com:8000, app2.openshift.example.com:8001app3.openshift.example.com:8002,其中端口号不能重复。

  • 这种方式在真正使用时不能满足业务需求,除非在F5的前面再加一层代理,这又增加了架构的复杂性。
  • 理想的状态是,所以的App应用的HTTP请求都访问F5的80端口,而HTTPS的请求访问F5的443端口,根据请求的域名路由到对应的Pool中(每个Pool是一个Service下的所有Pod的列表)。
  • 很高兴告诉大家,第二种方式能够满足上面的需求

为Openshift中的Route提供代理流量

使用BIG-IP作为Openshift的Router,能实现以下功能:

  • 为Services创建BIG-IP本地流量规则
  • 提供HTTP/HTTPS路由
  • 为Route资源添加BIG-IP健康检查

本文只介绍,如何使用F5提供HTTP/HTTPS路由。这也是最核心的部分。

部署环境版本:
2台F5:v13 192.168.200.82 192.168.200.83
Openshift集群: v3.9.1

创建新的HostSub Openshift

# hostsubnet.yml
apiVersion: v1
kind: HostSubnet
metadata:
  name: f5-bigip-node01
  annotations:
    pod.network.openshift.io/fixed-vnid-host: "0"
    pod.network.openshift.io/assign-subnet: "true"
# provide a name for the node that will serve as BIG-IP's entry into the cluster
host: f5-bigip-node01
# The hostIP address will be the BIG-IP interface address routable to the
# OpenShift Origin nodes.
# This address is the BIG-IP VTEP in the SDN's VXLAN.
hostIP: 192.168.200.82
---
apiVersion: v1
kind: HostSubnet
metadata:
  name: f5-bigip-node02
  annotations:
    pod.network.openshift.io/fixed-vnid-host: "0"
    pod.network.openshift.io/assign-subnet: "true"
# provide a name for the node that will serve as BIG-IP's entry into the cluster
host: f5-bigip-node02
# The hostIP address will be the BIG-IP interface address routable to the
# OpenShift Origin nodes.
# This address is the BIG-IP VTEP in the SDN's VXLAN.
hostIP: 192.168.200.83
---
apiVersion: v1
kind: HostSubnet
metadata:
  name: f5-bigip-float
  annotations:
    pod.network.openshift.io/fixed-vnid-host: "0"
    pod.network.openshift.io/assign-subnet: "true"
# provide a name for the node that will serve as BIG-IP's entry into the cluster
host: f5-bigip-float
# The hostIP address will be the BIG-IP interface address routable to the
# OpenShift Origin nodes.
# This address is the BIG-IP VTEP in the SDN's VXLAN.
hostIP: 192.168.200.84
oc create -f hostsubnet.yml

查看执行结果

[root@master01 ~]# oc get hostsubnet 
NAME                                 HOST                                 HOST IP         SUBNET          EGRESS IPS
f5-bigip-float                       f5-bigip-float                       192.168.200.84   10.128.6.0/23   []
f5-bigip-node01                      f5-bigip-node01                      192.168.200.82   10.129.6.0/23   []
f5-bigip-node02                      f5-bigip-node02                      192.168.200.83   10.130.4.0/23   []
master01.example.com   master01.example.com   192.168.200.1     10.130.0.0/23   []
master02.example.com   master02.example.com   192.168.200.2     10.128.0.0/23   []
master03.example.com   master03.example.com   192.168.200.3     10.128.2.0/23   []
node01.example.com     node01.example.com     192.168.200.21    10.129.0.0/23   []
node02.example.com     node02.example.com     192.168.200.22    10.131.0.0/23   []
router01.example.com   router01.example.com   192.168.200.11    10.129.2.0/23   []
router02.example.com   router02.example.com   192.168.200.12    10.130.2.0/23   []

创建一个VXLAN profile F5

在F5的TMOS终端,创建一个多点模式的vxlan

create /net tunnels vxlan openshift_vxlan flooding-type multipoint

创建一个VXLAN Tunnel F5

Local Address使用vip: 192.168.200.84
Secondary Address使用F5的设备IP:node1 192.168.200.82, node2 192.168.200.83
在F5 Node1上的TMOS创建Tunnel

create /net tunnels tunnel <float_tun_name> key 0 profile openshift_vxlan local-address 192.168.200.84 secondary-address 192.168.200.82 traffic-group traffic-group-1

在F5 Node2上的TMOS创建Tunnel

create /net tunnels tunnel <float_tun_name> key 0 profile openshift_vxlan local-address 192.168.200.84 secondary-address 192.168.200.83 traffic-group traffic-group-1

在每个F5设备VXLAN中创建Self IP F5

IP为设备对应在Openshift的HostSubnet下的一个IP(只要在对应的HostSubnet下就OK)
在F5 Node1中创建Self IP

create /net self 10.129.6.82/14 allow-service none vlan openshift_vxlan

在F5 Node2中创建Self IP

create /net self 10.130.4.83/14 allow-service none vlan openshift_vxlan

在当前主F5设备的VXLAN下创建Floating IP F5

如:当前主F5设备为node1,那Floating IP为主设备所在的HostSubnet下。

create /net self 10.128.6.84/14 allow-service none traffic-group traffic-group-1 vlan openshift_vxlan

创建一个新的Partition F5

create auth partition OpenShift

创建访问F5 BIG-IP的私钥 Openshift

oc create secret generic bigip-login --from-literal=username=admin --from-literal=password=admin -n kube-system

创建RBAC认证 Openshift

# cluster-role.yml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: bigip-ctlr
  namespace: kube-system
---
# For use in OpenShift clusters
apiVersion: v1
kind: ClusterRole
metadata:
  annotations:
    authorization.openshift.io/system-only: "true"
  name: system:bigip-ctlr
  namespace: kube-system
rules:
- apiGroups: ["", "extensions"]
  resources: ["nodes", "services", "endpoints", "namespaces", "ingresses", "routes" ]
  verbs: ["get", "list", "watch"]
- apiGroups: ["", "extensions"]
  resources: ["configmaps", "events", "ingresses/status"]
  verbs: ["get", "list", "watch", "update", "create", "patch" ]
- apiGroups: ["", "extensions"]
  resources: ["secrets"]
  resourceNames: ["bigip-login"]
  verbs: ["get", "list", "watch"]

---
apiVersion: v1
kind: ClusterRoleBinding
metadata:
  name: bigip-ctlr-role
  namespace: kube-system
userNames:
- system:serviceaccount:kube-system:bigip-ctlr
subjects:
- kind: ServiceAccount
  name: bigip-ctlr
roleRef:
  name: system:bigip-ctlr
oc create -f cluster-role.yml

部署BIG-IP Controller Openshift

  • 对应每台F5设备创建一个Deployment
  • Deployment中的 --bigip-url 为设备的IP
  • Deployment中的 --bigip-partition为之前F5下创建的Partition,Openshift
  • Deployment中的 --route-vserver-addr 为F5对外提供服务的IP
#deployment.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: f5-bigip-ctlr-01
spec:
  replicas: 1
  template:
    metadata:
      name: k8s-bigip-ctlr
      labels:
        app: k8s-bigip-ctlr
    spec:
      # Name of the Service Account bound to a Cluster Role with the required
      # permissions
      serviceAccountName: bigip-ctlr
      containers:
        - name: k8s-bigip-ctlr
          # replace the version as needed
          image: "f5networks/k8s-bigip-ctlr:1.5.1"
          env:
            - name: BIGIP_USERNAME
              valueFrom:
                secretKeyRef:
                  # Replace with the name of the Secret containing your login
                  # credentials
                  name: bigip-login
                  key: username
            - name: BIGIP_PASSWORD
              valueFrom:
                secretKeyRef:
                  # Replace with the name of the Secret containing your login
                  # credentials
                  name: bigip-login
                  key: password
          command: ["/app/bin/k8s-bigip-ctlr"]
          args: [
            # See the k8s-bigip-ctlr documentation for information about
            # all config options
            # http://clouddocs.f5.com/products/connectors/k8s-bigip-ctlr/latest
            "--bigip-username=$(BIGIP_USERNAME)",
            "--bigip-password=$(BIGIP_PASSWORD)",
            "--bigip-url=192.168.200.82",
            "--bigip-partition=OpenShift",
            "--pool-member-type=cluster",
            "--openshift-sdn-name=/Common/openshift_vxlan",
            '--manage-routes=true',
            '--route-vserver-addr=99.248.82.220'
            ]
      imagePullSecrets:
        # Secret containing the BIG-IP system login credentials
        - name: bigip-login

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: f5-bigip-ctlr-02
spec:
  replicas: 1
  template:
    metadata:
      name: k8s-bigip-ctlr
      labels:
        app: k8s-bigip-ctlr
    spec:
      # Name of the Service Account bound to a Cluster Role with the required
      # permissions
      serviceAccountName: bigip-ctlr
      containers:
        - name: k8s-bigip-ctlr
          # replace the version as needed
          image: "f5networks/k8s-bigip-ctlr:1.5.1"
          env:
            - name: BIGIP_USERNAME
              valueFrom:
                secretKeyRef:
                  # Replace with the name of the Secret containing your login
                  # credentials
                  name: bigip-login
                  key: username
            - name: BIGIP_PASSWORD
              valueFrom:
                secretKeyRef:
                  # Replace with the name of the Secret containing your login
                  # credentials
                  name: bigip-login
                  key: password
          command: ["/app/bin/k8s-bigip-ctlr"]
          args: [
            # See the k8s-bigip-ctlr documentation for information about
            # all config options
            # http://clouddocs.f5.com/products/connectors/k8s-bigip-ctlr/latest
            "--bigip-username=$(BIGIP_USERNAME)",
            "--bigip-password=$(BIGIP_PASSWORD)",
            "--bigip-url=192.168.200.83",
            "--bigip-partition=OpenShift",
            "--pool-member-type=cluster",
            "--openshift-sdn-name=/Common/openshift_vxlan",
            '--manage-routes=true',
            '--route-vserver-addr=192.168.200.80'
            ]
      imagePullSecrets:
        - name: bigip-login
oc create -f deployment.yml

查看BIG-IP Controller的部署进度

[root@master01 ~]# oc get pod
NAME                                READY     STATUS    RESTARTS   AGE
f5-bigip-ctlr-01-7f44695b97-lmwdh   1/1       Running   0          17h
f5-bigip-ctlr-02-54df674f58-j2x26   1/1       Running   0          17h

当BIG-IP Controller POD启动后,在F5上会自动创建两个virtual servers

  • "ose-vserver" 为HTTP请求
  • "https-ose-vserver" 为HTTPS请求
    这两个virtual servers是Openshift下所有的Route共用的。

创建新的应用F5-Test,并创建HTTP Route Openshift

oc new-project f5-test
oc new-app harbor.example.com/public/nginx:1.14 --name=f5-test --allow-missing-images
oc expose dc/f5-test --port=8080

创建Route

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  labels:
    name: f5-test
  name: f5-test
  annotations:
    virtual-server.f5.com/balance: least-connections-node
spec:
  host: f5-test.example.com
  port:
    targetPort: 8080
  to:
    kind: Service
    name: f5-test

本地绑定hosts

192.168.200.80 f5-test.example.com

浏览器访问http://f5-test.example.com,即能看到应用页面。

创建HTTPS Route(仍然使用上面的应用) Openshift

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  annotations:
    virtual-server.f5.com/balance: least-connections-node
  labels:
    app: f5-test
  name: f5-test-2
spec:
  host: f5-tes-2t.example.com
  tls:
    insecureEdgeTerminationPolicy: Allow
    termination: edge
  to:
    kind: Service
    name: f5-test

本地绑定hosts

192.168.200.80 f5-test-2.example.com

浏览器访问https://f5-test.example.com,即能看到应用页面。

说明

  • Openshit上创建Service后,F5会自动创建新的Pool,Pool里的资源即为Service下的Pod
  • 请求到达F5后,F5根据请求的域名,找到对应的Pool,请求直接到达Pod。不会请求集群里的Route。

参考资料

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容

  • 本文整理了在实践过程中使用的Linux网络工具,这些工具提供的功能非常强大,我们平时使用的只是冰山一角,比如lso...
    老夫刘某阅读 3,470评论 0 7
  • 下面是“黑夜路人”的《大型网站架构优化(PHP)与相关开源软件使用建议》 ====================...
    wokeman阅读 4,813评论 1 8
  • 今天是小年,上午写作业,中午一家人吃饺子,下午我和妈妈去染头发,小妞由孩爹带。染完头发把妈妈送回家,我急急忙忙赶去...
    成乐阅读 167评论 0 0
  • 文/米衙 提到商业,就要提到应用场景。应用场景就是什么人在什么地方通过什么产品使用什么服务,产生了什么内容(数据)...
    米衙阅读 986评论 0 1
  • 因为工作的原因,我去过国内的很多岛屿。在那些岛上短暂的工作生活和游玩过。我去过海南岛的三亚,厦门本岛和鼓浪屿,舟山...
    浏如阅读 841评论 1 3