### APiSIX 介绍

Apache APISIX 是一个动态、实时、高性能的开源 API 网关，提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。

### APISIX 及 Dashboard 部署

**涉及组件版本**

- etcd 3.5.1
- apisix 3.1.0
- dashboard 2.15.0
- ingress-controller 1.6.0

**部署方式**

1、helm 方式部署

官方提供了 [helm 方式部署文档](https://apisix.apache.org/zh/docs/apisix/installation-guide/) ，可以参考官方文档进行部署。

2、 yaml 方式部署

在生产环境中，我们需要对 APiSIX 进行定制化部署, 比如：修改配置文件、启动参数等等。这时候，更加建议采用 yaml 方式部署 APISIX。

**部署步骤**

首先克隆仓库 [apisix-deploy](https://github.com/pingcap-inc/apisix-deploy/) ， 然后执行以下命令部署

```bash

# 部署 apisix、dashboard、etcd

kubectl create ns apisix

kubectl apply -f apisix-etcd.yaml

kubectl apply -f apisix.yaml

kubectl apply -f apisix-dashboard.yaml

# 等待 Pod 全部启动，将 apisix-dashboard 端口转发到本机。

kubectl port-forward service/apisix-dashboard 8080:80

#最后访问 localhost:8080，即可查看 Dashboard 相关信息。默认登录账号密码为 admin：admin。

# 部署 apisix-ingress-controller

# 创建 ApisixRoute CRD
git clone https://github.com/apache/apisix-ingress-controller.git --depth 1
cd apisix-ingress-controller/
kubectl apply -k samples/deploy/crd

kubectl apply -f apisix-ingress-controller.yaml


```

参考文档：

[两种方式教你在 K8s 中轻松部署 Apache APISIX](https://apisix.apache.org/zh/blog/2021/12/15/deploy-apisix-in-kubernetes/)

[从概念到实践帮你快速上手 Apache APISIX Ingress](https://apisix.apache.org/zh/blog/2021/10/09/apisix-ingress-techblog/#apisix-ingress-vs-k8s-ingress-nginx)

config 文件 :

[apisix 配置文件](https://github.com/apache/apisix/blob/release/3.1/conf/config-default.yaml)

[apisix-ingress-controller 配置文件](https://github.com/apache/apisix-ingress-controller/blob/v1.5.0/conf/config-default.yaml)

[apisix-dashboard 配置文件](https://github.com/apache/apisix-dashboard/blob/release/2.15/api/conf/conf.yaml)



### 更换证书

证书信息：
namespace: apisix
资源类型：secret
服务名称：apisx-secret
证书来源：@mengfansheng 提供的 *.pingcap.net 证书


共有两处地方使用到证书：apisix 9443、apisix-dashboard 9000
apisix 9443 影响重大，出现问题会导致网关挂掉；apisix-dashboard 9000 出现问题，只会导致 dashboard 无法访问。


每年到期后，都需要更换证书，可以参考以下步骤：


注意，当你更新 Secret 的内容时，需要确保新的 tls.crt 和 tls.key值是 Base64 编码的。

 你可以使用以下命令将文件内容转换为 Base64 编码：
base64 /path/to/your/tls.crt  
base64 /path/to/your/tls.key 

或者通过在线工具：https://base64.us/ 进行转换


1、将新的编码后的证书贴到 apisx-secret 中
位置在 apisix-dashboard.yaml 文件中，221、222 行

![img_2.png](img_2.png)

2、 apply yaml 文件使其生效
```bash
kubectl apply -f apisix-dashboard.yaml
```

3、重启 apisix、apisix-dashboard
```bash
kubectl delete pod apisix-xxxx -n apisix
kubectl delete pod apisix-dashboard-xxxx -n apisix
```

4、 最后查看状态，确认服务启动，并且证书已经更换成功

![img_1.png](img_1.png)


#### apisix 非常重要的资源

![img.png](img.png)



