ACK 部署 Apache apisix-ingress-cotroller
本文轉(zhuǎn)載自微信公眾號(hào)「Kirito的技術(shù)分享」,作者金衛(wèi)。轉(zhuǎn)載本文請(qǐng)聯(lián)系Kirito的技術(shù)分享公眾號(hào)。金衛(wèi)
背景
Ingress 是 Kubernetes 中一個(gè)值得關(guān)注的模塊,作為外部訪問(wèn) Kubernetes 集群服務(wù)的入口,市面上已經(jīng)有了多種 Ingress controller 的實(shí)現(xiàn)。國(guó)產(chǎn)實(shí)時(shí)、高性能的 API 網(wǎng)關(guān) Apache APISIX 推出的 Apache/apisix-ingress-controller 就是其中一員,作為功能更加強(qiáng)大的 ingress 對(duì)外提供服務(wù)。筆者準(zhǔn)備在阿里云 ACK 集群上部署測(cè)試。
主題描述
本文主要介紹在阿里云 ACK 部署 apisix-ingress-controller,并且使用 httpbin 測(cè)試一個(gè)簡(jiǎn)單的場(chǎng)景。
部署拓?fù)?/strong>
網(wǎng)絡(luò)拓?fù)?/p>
依賴項(xiàng)
阿里云的 ACK 集群 ;推薦最低配置:3個(gè) master 節(jié)點(diǎn):CPU 2核 內(nèi)存 4G2個(gè) worker 節(jié)點(diǎn):CPU 4核 內(nèi)存 8G
安裝步驟
apisix 2.1 release
通過(guò) helm 安裝 apisix 2.1 release
- $ kubectl create ns apisix
- $ git clone https://github.com/apache/apisix-helm-chart.git
- $ cd ./apisix-helm-chart
- $ helm repo add bitnami https://charts.bitnami.com/bitnami
- $ helm dependency update ./chart/apisix
- $ helm install apisix ./chart/apisix \
- --set gateway.type=LoadBalancer \
- --set allow.ipList="{0.0.0.0/0}" \
- --namespace apisix
tips: etcd 安裝時(shí)指定 PVC, PVC 在阿里云部署時(shí),需要指定 PV 為云盤(pán), 請(qǐng)?jiān)?PVC 的 annotations 中增加:volume.beta.kubernetes.io/storage-class: alicloud-disk-ssd。(關(guān)于 PVC 和 PV 的關(guān)系請(qǐng)參考這里)
apisix-ingress-controller
通過(guò) helm 安裝 apisix-ingress-controller
- $ git clone https://github.com/apache/apisix-ingress-controller.git
- $ cd ./apisix-ingress-controller
- $ helm install ingress-apisix-base -n apisix ./charts/base
- $ helm install ingress-apisix ./charts/ingress-apisix \
- --set ingressController.image.tag=dev \
- --set ingressController.config.apisix.baseURL=http://apisix-admin:9180/apisix/admin \
- --set ingressController.config.apisix.adminKey=edd1c9f034335f136f87ad84b625c8f1 \
- --namespace apisix
測(cè)試
檢查集群是否部署成功
配置一個(gè)簡(jiǎn)單的路由做測(cè)試
- apiVersion: apisix.apache.org/v1
- kind: ApisixRoute
- metadata:
- name: httpbin-route
- namespace: apisix
- spec:
- rules:
- - host: httpbin.apisix.com
- http:
- paths:
- - backend:
- serviceName: httpbin
- servicePort: 80
- path: /hello*
通過(guò) apisix admin api 查看結(jié)果,發(fā)現(xiàn)路由已經(jīng)正確配置。
- {
- "action": "get",
- "count": "2",
- "header": {
- "revision": "46",
- "cluster_id": "8320356269565269865",
- "raft_term": "2",
- "member_id": "3807956127770623265"
- },
- "node": {
- "key": "/apisix/upstreams",
- "dir": true,
- "modifiedIndex": 27,
- "createdIndex": 3,
- "nodes": [
- {
- "key": "/apisix/upstreams/00000000000000000041",
- "modifiedIndex": 42,
- "value": {
- "nodes": {
- "172.20.1.12:80": 100
- },
- "type": "roundrobin",
- "pass_host": "pass",
- "hash_on": "vars",
- "desc": "apisix_httpbin_80",
- "create_time": 1608561159,
- "update_time": 1608561159
- },
- "createdIndex": 42
- }
- ]
- }
- }
擴(kuò)容 httpbin
查看 k8s 中 httpbin
查看 apisix 中 httpbin upstream
- // 格式化后
- {
- ...
- "nodes": {
- "172.20.1.12:80": 100,
- "172.20.0.198:80": 100,
- "172.20.0.197:80": 100
- },
- "id": "00000000000000000041",
- "key": "/apisix/upstreams/00000000000000000041",
- "desc": "apisix_httpbin_80",
- ...
- }
總結(jié)
本文在 ACK 集群環(huán)境依次安裝了 Etcd、 Apache APISIX、Apache apisix-ingress-controller,并且使用 httpbin 服務(wù)驗(yàn)證 ingress 的基本配置功能,通過(guò) CRD 配置了路由,檢測(cè)了后端服務(wù)在擴(kuò)縮容時(shí)服務(wù)注冊(cè)發(fā)現(xiàn)機(jī)制。
另外值得一提的是 apisix-ingress-controller 可以完整的支持 Apache APISIX 提供的所有插件,甚至是自定義插件。功能豐富且擴(kuò)展能力強(qiáng),是一款不錯(cuò)的 Ingress 項(xiàng)目。