赞
踩
实现原理,又nginx进行跳转到apisix网关,在由apisix的上游、路由服务转发到k8s。
环境:
k8s集群 | 10.0.0.101,102,103 |
nginx | 10.0.0.5 |
apisix | 部署到k8s上 |
apisix
Apache APISIX是一个动态的、实时的、高性能的 API 网关.
使用Helm Chart安装
所有的pod,svc等都放到了default的namespace下
apisix
- helm repo add apisix https://charts.apiseven.com
- helm repo update
- helm install apisix apisix/apisix
apisix-dashboard
helm install apisix-dashboard apisix/apisix-dashboard
apisix-ingress-controler
不用安装
安装成功后截图
部署whoami
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: whoami
- spec:
- selector:
- matchLabels:
- run: whoami
- replicas: 2
- template:
- metadata:
- labels:
- run: whoami
- spec:
- containers:
- - name: whoami
- image: containous/whoami
- ports:
- - containerPort: 80
- ----------------------------
- apiVersion: v1
- kind: Service
- metadata:
- name: whoami
- labels:
- run: whoami
- spec:
- ports:
- - port: 80
- protocol: TCP
- selector:
- run: whoami

进入nginx负载均衡服务器
vim apisix.conf 32388是apisix-gateway的暴露端口;
- upstream upstream-test3-apisix {
- server 10.0.0.101:32388;
- }
-
-
- server {
- listen 80;
- server_name ~^(.+)?-test-4.apisix.xthklocal.cn;
- client_max_body_size 200M;
-
- location / {
- proxy_set_header X-Forwarded-For $remote_addr;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header Host $host;
- proxy_redirect off;
- proxy_read_timeout 600;
- proxy_connect_timeout 600;
- proxy_pass http://upstream-test3-apisix;
- proxy_buffers 256 4k;
- proxy_max_temp_file_size 0;
- proxy_cache_valid 200 302 10m;
- proxy_cache_valid 301 1h;
- proxy_cache_valid any 1m;
- }
-
- }

然后登录apisix-dashboard
点击上游-新增
点击 路由 -新增:名称 随便填写,域名填上
点击下一步
选择 我们建立的上游
一直下一步到完成即可
将域名解析添加到本地hosts
10.0.0.5 whoami-test-4.apisix.xthklocal.cn
访问即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。