ACK 部署 Apache apisix-ingress-cotroller
本文轉載自微信公眾號「Kirito的技術分享」,作者金衛。轉載本文請聯系Kirito的技術分享公眾號。金衛
背景
Ingress 是 Kubernetes 中一個值得關注的模塊,作為外部訪問 Kubernetes 集群服務的入口,市面上已經有了多種 Ingress controller 的實現。國產實時、高性能的 API 網關 Apache APISIX 推出的 Apache/apisix-ingress-controller 就是其中一員,作為功能更加強大的 ingress 對外提供服務。筆者準備在阿里云 ACK 集群上部署測試。
主題描述
本文主要介紹在阿里云 ACK 部署 apisix-ingress-controller,并且使用 httpbin 測試一個簡單的場景。
部署拓撲
網絡拓撲
依賴項
阿里云的 ACK 集群 ;推薦最低配置:3個 master 節點:CPU 2核 內存 4G2個 worker 節點:CPU 4核 內存 8G
安裝步驟
apisix 2.1 release
通過 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 安裝時指定 PVC, PVC 在阿里云部署時,需要指定 PV 為云盤, 請在 PVC 的 annotations 中增加:volume.beta.kubernetes.io/storage-class: alicloud-disk-ssd。(關于 PVC 和 PV 的關系請參考這里)
apisix-ingress-controller
通過 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
測試
檢查集群是否部署成功
配置一個簡單的路由做測試
- 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*
通過 apisix admin api 查看結果,發現路由已經正確配置。
- {
- "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
- }
- ]
- }
- }
擴容 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",
- ...
- }
總結
本文在 ACK 集群環境依次安裝了 Etcd、 Apache APISIX、Apache apisix-ingress-controller,并且使用 httpbin 服務驗證 ingress 的基本配置功能,通過 CRD 配置了路由,檢測了后端服務在擴縮容時服務注冊發現機制。
另外值得一提的是 apisix-ingress-controller 可以完整的支持 Apache APISIX 提供的所有插件,甚至是自定義插件。功能豐富且擴展能力強,是一款不錯的 Ingress 項目。