yzeng25 commented on a change in pull request #811: URL: https://github.com/apache/apisix-website/pull/811#discussion_r769438823
########## File path: website/i18n/zh/docusaurus-plugin-content-blog/2021/12/15/deploy-apisix-in-kubernetes.md ########## @@ -0,0 +1,184 @@ +--- +title: "两种方式教你在 K8s 中轻松部署 Apache APISIX" +authors: + - name: "喻柏仲" + title: "Author" + url: "https://github.com/zaunist" + image_url: "https://avatars.githubusercontent.com/u/38528079?v=4" + - name: "苏钰" + title: "Technical Writer" + url: "https://github.com/SylviaBABY" + image_url: "https://avatars.githubusercontent.com/u/39793568?v=4" +keywords: +- Apache APISIX +- Kubernetes +- APISIX Dashboard +- 部署安装 +- 集群 +description: Apache APISIX 目前支持多种方式进行安装部署,本文主要介绍如何在 Kubernetes 环境中部署 Apach APISIX 以及 APISIX-Dashboard。 +tags: [Technology] +--- + +> Apache APISIX 目前支持多种方式进行安装部署,本文主要介绍如何在 Kubernetes 环境中部署 Apach APISIX 以及 APISIX-Dashboard。 + +<!--truncate--> + +Apache APISIX 是一个动态、实时、高性能的开源 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。 + +而 Kubernetes 作为自动部署、扩展和管理容器化应用程序的开源系统,旨在为用户提供**跨主机集群**的自动部署、扩展以及运行应用程序容器等相关功能支持。如何快速地在 K8s 中部署 Apache APISIX 并通过 Dashboard 进行相关信息的展示,这里我们为大家整理了两种非常容易上手的安装思路。 + +## 环境准备 + +在正式进入安装部署前,确保网络畅通并准备好相应的 K8s 集群。 + +在这里,我们推荐使用 Kind 进行本地搭建 K8s 集群测试环境,非常方便且容易上手。根据[官方文档](https://kind.sigs.k8s.io/docs/user/quick-start/)步骤安装好 Kind 后,只需一条指令即可搭建好 K8s 集群环境。 + +```shell +kind create cluster +``` + +## 方式一:通过 Helm 安装 + +Helm 主要用于管理 Kubernetes 中的应用程序。类似 apt、yum、pacman 这些 Linux 中的包管理器,所以 Helm 也称为 Kubernetes 中的包管理器。 + +目前 Apache APISIX 已经提供了 [Helm Chart 仓库](https://github.com/apache/apisix-helm-chart),用户可以非常方便地通过 Helm 来部署和卸载 Apache APISIX。 + +### 部署 Apache APISIX + +首先添加 Apache APISIX Helm Chart 地址并更新仓库。 + +```shell +helm repo add apisix https://charts.apiseven.com +helm repo update +``` + +进行安装 Apache APISIX(此处演示是将 Apache APISIX 安装到 Default Namespace,如需自定义 Namespace,可参考[相关文档](https://kubernetes.io/docs/tasks/administer-cluster/namespaces/#creating-a-new-namespace))。 + +```shell +helm install apisix apisix/apisix +``` + +上述指令执行成功后,会得到如下返回信息: + +```shell +▶ helm install apisix apisix/apisix +NAME: apisix +LAST DEPLOYED: Sun Dec 5 14:43:19 2021 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +TEST SUITE: None +NOTES: +1. Get the application URL by running these commands: + export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services apisix-gateway) + export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +``` + +通过上述方式安装部署的 Apache APISIX,Admin API 会暴露在集群中 `9180` 端口,Gateway 暴露在 `80` 端口。如果要访问 Admin API,可以使用 `kubectl port-forward` 将端口转发到本地主机上的端口。 + +这里演示的是转发到本机 `9080` 端口情况,主要是为了和 Apache APISIX 官方文档同步,方便后续验证。 + +```shell +kubectl port-forward service/apisix-admin 9080:9180 +``` + +之后可参考 [Apache APISIX 快速入门指南](https://apisix.apache.org/zh/docs/apisix/getting-started/),进行 Upstream 的添加与绑定 Route 等相关操作。 + +最后进行新建路由的验证环节。 + +由于在本文演示中使用了 Kind 来搭建本地 K8s 集群,`apisix-gateway` 的 NodePort 访问不了,所以在验证之前还需要额外一步,即将集群中的 `80` 端口转发到本机 `8080` 端口。 +kubectl port-forward service/apisix-gateway 8080:80 + +开始进行验证。 + +```shell +curl -X GET "http://127.0.0.1:8080/get?foo1=bar1&foo2=bar2" -H "Host: httpbin.org" +``` + +期望的返回结果可以参考下方示例。 + +```json +{ + "args": { + "foo1": "bar1", + "foo2": "bar2" + }, + "headers": { + "Accept": "*/*", + "Accept-Encoding": "gzip", + "Host": "httpbin.org", + "User-Agent": "curl/7.64.1", + "X-Amzn-Trace-Id": "Root=1-61ac63b5-348d3c5567db393462cd0666", + "X-Forwarded-Host": "httpbin.org" + }, + "origin": "127.0.0.1, 192.46.208.201", + "url": "http://httpbin.org/get?foo1=bar1&foo2=bar2" +} +``` + +### 部署 Apache APISIX-Dashboard + +与部署 Apache APISIX 一样,通过 Helm 安装 Apache APISIX-Dashboard 也只需执行一条指令。 + +```shell +helm install apisix-dashboard apisix/apisix-dashboard +``` + +接下来转发 Dashboard 端口到本机。 + +```shell +kubectl port-forward service/apisix-dashboard 8080:80 +``` + +最后访问本地 `localhost:8080` 就可以看到登录页面了。 + +:::note 注意 +这里部署出来的 Apache APISIX-Dashboard 系统信息中不会出现 Apache APISIX 的节点信息。因为通过 Helm 方式进行安装的话默认是没有启用 `server-info` 插件,如有需要可在 apisix 的configmap 中自行添加。`server-info` 的配置可参考[相关文档](https://apisix.apache.org/docs/apisix/plugins/server-info/)。 +::: + +## 方式二:通过 yaml 文件部署 + +相较于上述 Helm 方式的部署,使用 yaml 文件来部署 Apache APISIX,可以更加方便地进行自定义配置。 + +### 部署 APISIX 及 Dashboard + +:::note 注意 +如果已经使用方式一部署过,在进行下述安装前需要先清除 ETCD 的 PVC 存储以方便后续操作。 +::: + +这里我们已经整理好了在部署 Apache APISIX、APISIX-Dashboard 及 etcd 集群时需要用到的 yaml 文件,大家可通过 [apisix-on-kubernetes 仓库](https://github.com/zaunist/apisix-on-kubernetes)进行调用接下来提到的相关文件。 + +首先克隆上述提到的 `apisix-on-kubernetes` 仓库。 + +```shell +git clone https://github.com/zaunist/apisix-on-kubernetes.git +``` + +然后执行以下命令。 + +```shell +kubectl apply -f etcd.yaml +kubectl apply -f apisix.yaml +kubectl apply -f apisix-dashboard.yaml +``` + +等待 Pod 全部启动,将 `apisix-dashboard` 端口转发到本机。 + +```shell +kubectl port-forward service/apisix-dashboard 8080:80 +``` + +最后访问 `localhost:8080`,即可查看 Dashboard 相关信息。默认登录账号密码为 `admin`、`admin`。 + +:::note 提示 Review comment: ```suggestion :::note 提示 ``` try `:::tip 提示` ########## File path: website/blog/2021/12/15/deploy-apisix-in-kubernetes.md ########## @@ -0,0 +1,184 @@ +--- +title: "How to Easily Deploy Apache APISIX in Kubernetes" +authors: + - name: "Bozhong Yu" + title: "Author" + url: "https://github.com/zaunist" + image_url: "https://avatars.githubusercontent.com/u/38528079?v=4" + - name: "Sylvia" + title: "Technical Writer" + url: "https://github.com/SylviaBABY" + image_url: "https://avatars.githubusercontent.com/u/39793568?v=4" +keywords: +- Apache APISIX +- Kubernetes +- APISIX Dashboard +- Deployment +- Cluster +description: Apache APISIX currently supports multiple ways to install and deploy. This article focuses on how to deploy Apach APISIX and APISIX-Dashboard in a Kubernetes environment. +tags: [Technology] +--- + +> Apache APISIX currently supports multiple ways to install and deploy. This article focuses on how to deploy Apach APISIX and APISIX-Dashboard in a Kubernetes environment. + +<!--truncate--> + +Apache APISIX is a dynamic, real-time, high-performance open source API gateway that provides rich traffic management features such as load balancing, dynamic upstream, grayscale publishing, service meltdown, authentication, observability, and more. + +And Kubernetes, an open source system for automatically deploying, scaling, and managing containerized applications, is designed to provide users with support for automatic deployment **across host clusters**, scaling, and related features such as running application containers. Here we have compiled two easy-to-follow installation ideas on how to quickly deploy Apache APISIX in K8s and present related information via Dashboard. + +## Environment Preparation + +Before deploying, make sure your network is up and ready for K8s clustering. +Here, we recommend using Kind to build the K8s cluster test environment locally, it is very convenient and easy to get started. After installing Kind according to the [official documentation](https://kind.sigs.k8s.io/docs/user/quick-start/), you can set up the K8s cluster environment with a single command. + +```shell +kind create cluster +``` + +### Option 1: Installation via Helm + +Helm is mainly used to manage applications in Kubernetes. Helm is also known as the package manager in Kubernetes, similar to apt, yum, and pacman, which are package managers in Linux. + +Currently, Apache APISIX has provided [Helm Chart repository](https://github.com/apache/apisix-helm-chart), and users can easily deploy and uninstall Apache APISIX via Helm. + +### Deploying Apache APISIX + +First add the Apache APISIX Helm Chart address and update the repository. + +```shell +helm repo add apisix https://charts.apiseven.com +helm repo update +``` + +Install Apache APISIX (this demo installs Apache APISIX into Default Namespace, for custom Namespace, please [refer to the documentation](https://kubernetes.io/docs/tasks/administer-cluster/namespaces/#creating-a-new-namespace)). + +```shell +helm install apisix apisix/apisix +``` + +When the above command is executed successfully, the following return message will be obtained. + +```shell +▶ helm install apisix apisix/apisix +NAME: apisix +LAST DEPLOYED: Sun Dec 5 14:43:19 2021 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +TEST SUITE: None +NOTES: +1. Get the application URL by running these commands: + export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services apisix-gateway) + export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +``` + +With an Apache APISIX deployment installed in the above manner, the Admin API is exposed on port `9180` in the cluster and the Gateway is exposed on port `80`. To access the Admin API, you can use `kubectl port-forward` to forward the port to a port on the local host. + +Here is a demonstration of port-forwarding to port `9080` on the local machine, mainly to synchronize with the official Apache APISIX documentation and to facilitate subsequent verification. + +```shell +kubectl port-forward service/apisix-admin 9080:9180 +``` + +After that, you can refer to the [Apache APISIX Quick Start Guide](https://apisix.apache.org/zh/docs/apisix/getting-started/) to add and bind a Route to Upstream and other related operations. + +Finally, the verification of the new route is performed. + +Since this article uses Kind to build a local K8s cluster, the `apisix-gateway` NodePort is not accessible, so an additional step is needed before validation, i.e. forwarding port `80` from the cluster to port `8080` on the local machine. + +Start the verification process. + +```shell +curl -X GET "http://127.0.0.1:8080/get?foo1=bar1&foo2=bar2" -H "Host: httpbin.org" +``` + +The expected return results can be seen in the example below. + +```json +{ + "args": { + "foo1": "bar1", + "foo2": "bar2" + }, + "headers": { + "Accept": "*/*", + "Accept-Encoding": "gzip", + "Host": "httpbin.org", + "User-Agent": "curl/7.64.1", + "X-Amzn-Trace-Id": "Root=1-61ac63b5-348d3c5567db393462cd0666", + "X-Forwarded-Host": "httpbin.org" + }, + "origin": "127.0.0.1, 192.46.208.201", + "url": "http://httpbin.org/get?foo1=bar1&foo2=bar2" +} +``` + +### Deploying Apache APISIX-Dashboard + +As with deploying Apache APISIX, installing Apache APISIX-Dashboard via Helm requires only one command. + +```shell +helm install apisix-dashboard apisix/apisix-dashboard +``` + +Next, forward the Dashboard port to the local machine. + +```shell +kubectl port-forward service/apisix-dashboard 8080:80 +``` + +Finally, visit your `localhost:8080` to see the login page. + +:::note +The node information of Apache APISIX will not appear in the system information of Apache APISIX-Dashboard deployed here. The `server-info` plug-in is not enabled by default if installed by Helm, so you can add it in the apisix configmap if needed. + +For the configuration of `server-info`, please refer to the [relevant documentation](https://apisix.apache.org/docs/apisix/plugins/server-info/). +::: + +## Option 2: Deployment via yaml file + +Deploying Apache APISIX using a yaml file is easier than the Helm deployment method described above, and allows you to customize the configuration more easily. + +### Deploying APISIX and Dashboard + +:::note +If you have already deployed using method 1, you will need to clear the ETCD PVC storage before proceeding with the following installation. +::: + +The yaml files needed to deploy Apache APISIX, APISIX-Dashboard, and etcd clusters are already organized here, and you can call the next mentioned files through the [apisix-on-kubernetes repository](https://github.com/zaunist/apisix-on-kubernetes). + +First clone the `apisix-on-kubernetes` repository mentioned above. + +```shell +git clone https://github.com/zaunist/apisix-on-kubernetes.git +``` + +Then execute the following command. + +```shell +kubectl apply -f etcd.yaml +kubectl apply -f apisix.yaml +kubectl apply -f apisix-dashboard.yaml +``` + +Wait for the Pod to fully boot and forward the `apisix-dashboard` port to the local machine. + +```shell +kubectl port-forward service/apisix-dashboard 8080:80 +``` + +Finally, visit `localhost:8080` to see the Dashboard related information. The default login password is `admin`,`admin`. + +:::note Review comment: try :::tip 提示 ```suggestion :::note ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
