目 录CONTENT

文章目录

【流量网关】k8s与apisix统一的流量入口方案(内网版)

Administrator
2025-08-11 / 0 评论 / 1 点赞 / 42 阅读 / 0 字
温馨提示:
部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

【流量网关】k8s与apisix统一的流量入口方案(内网版)

apisix简述

APISIX是一个开源的高性能API网关软件,旨在提供可扩展、可靠和灵活的API管理解决方案。

它由Apache APISIX团队开发,基于Nginx和OpenResty构建,并提供了强大的功能,如路由、负载均衡、限流、鉴权、日志记录等。APIsix的设计目标是使开发人员能够轻松构建和管理大规模的分布式API架构。

APIsix-Dashboard(也称为APIsix Dashboard或APISIX Dashboard)是一个用于管理和监控APIsix的Web界面。它是APIsix的可选组件,提供了一个直观的用户界面,使用户可以通过图形化界面进行API的配置、监控和管理。APIsix-Dashboard使得管理APIsix变得更加简单,并提供了一些高级功能,如可视化的API路由配置、实时监控指标、访问日志查看等。

简单来说可以这样子理解,apisix是一个nginx(默认开的9080(http)、9443(https)端口),而apisix-dashboard是一个可视化配置apisix的web界面(9000端口)。

无网络安装

1、下载相关依赖包

依赖包如下,下载即可,里面有etcd的安装包,有apisix及apisix-dashboard的rpm包。
apisix.zip

2、配置dns配置文件

这里配置dns也可以不用做,这里做的原因,是想把流量,从svc引入到k8s中。为什么能这样做,是因为k8s里面有一个coredns,能解析svc的域名

vim /etc/resolv.conf

cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
nameserver 10.96.0.10
nameserver 183.60.83.19
nameserver 183.60.82.98```

# 其中183.60.83.19及183.60.82.98是自已就有的  10.96.0.10是k8s自带的coredns的clusterip
# 这个值,可能通过以下命令查询(在master节点上执行)
kubectl get svc -A -owide | grep kube-dns
***  ClusterIP 10.96.0.10  <none>  53/UDP,53/TCP,9153/TCP  ***

3、apisix及apisix-dashboard

3.1 解压

# 随便上传到某个目录,比如说/root下面
unzip apisix.zip

3.2 安装etcd

# 进入到刚刚解压的apisix目录
cd apisix
# 解压并启动etcd
tar -xvf etcd-v3.5.4-linux-amd64.tar.gz && \
cd etcd-v3.5.4-linux-amd64 && \
sudo cp -a etcd etcdctl /usr/bin/
nohup etcd >/tmp/etcd.log 2>&1 &

3.3 安装、启动apisix及apisix-dashboard

# 进入到刚刚解压的apisix目录
cd apisix

# 安装apisix及apisix-dashboard
rpm -ivh --force --nodeps *.rpm

# 启动apisix,此时已经可通过节点ip+9080(默认是9080端口而不是80端口,后面会改成80端口)访问到数据了
apisix init
apisix start

# 启动apisix-dashboard
# 默认情况下,ip+9000直接在浏览器中不能打开
# 但直接在该台机器通过curl 的方式可以打开,原因是在其配置文件中有相关设置
systemctl start apisix-dashboard

3.4 配置apisix

apisix的配置文件为:/usr/local/apisix/conf/config.yaml
...
deployment:
role: traditional
...
换成以下即可,这个配置,相当于将这个apisix(nginx),其监听端口,由默认的9080更改为80端口
...
apisix:
  node_listen: 80 # APISIX listening port
deployment:
  role: traditional
...
添加后需要重启
apisix stop
apisix start
# 不能直接使用apisix restart,可能会有问题

3.5 配置apisix-dashboard

apisix-dashboard的配置文件为/usr/local/apisix/dashboard/conf/conf.yaml
默认情况下只允许本机访问,现在想提供web界面配置apisix(nginx),需要注释,如下。

...
allow_list:             # If we don't set any IP list, then any IP access is allowed by default.
- 127.0.0.1           # The rules are checked in sequence until the first match is found.
- ::1                 # In this example, access is allowed only for IPv4 network 127.0.0.1, and for IPv6 network ::1.
# It also support CIDR like 192.168.1.0/24 and 2001:0db8::/32
...
更改之后的(注释掉下面的)
allow_list:             # If we don't set any IP list, then any IP access is allowed by default.
#- 127.0.0.1           # The rules are checked in sequence until the first match is found.
#- ::1                 # In this example, access is allowed only for IPv4 network 127.0.0.1, and for IPv6 network ::1.
# It also support CIDR like 192.168.1.0/24 and 2001:0db8::/32
更改之后需要重新启动
systemctl stop apisix-dashboard
systemctl start apisix-dashboard

启动后可以用ip+9000(默认)访问到前端界面(默认的用户名及密码均为admin)。

3.6 说明

以下是猜测,在实际实验过程中,如果将修改/etc/resolv.conf(添加k8s的coredns的地址)放在apisix安装之后,实际上是不会进行解析的,猜测是apisix init/start后,将/etc/resolv.conf读取到了内存当中,后改/etc/resolv.conf就不会生效。如果这种事情发生了,可以apisix stop后再apisix start即可重新加载/etc/resolv.conf

1
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区