# 在 ROSA 上安装 APISIX

[Red Hat OpenShift Service on AWS (ROSA)](https://aws.amazon.com/rosa/) 是一项完全托管的服务，提供了一种在 AWS 上部署和管理 OpenShift 集群的简化方法。

## 前置条件[​](#前置条件 "前置条件的直接链接")

* 拥有一个 AWS 帐户

* 拥有一个 Red Hat 帐户

* 按照 [ROSA 入门](https://cloud.redhat.com/learn/getting-started-red-hat-openshift-service-aws-rosa) 学习路径进行操作：

  <!-- -->

  * 配置供 OpenShift 使用的 AWS 环境
  * 部署集群
  * 向用户授予集群管理员权限

* 安装 [ROSA CLI](https://console.redhat.com/openshift/downloads)

* 安装 [OpenShift CLI](https://docs.redhat.com/en/documentation/openshift_container_platform/4.11/html/cli_tools/openshift-cli-oc#cli-installing-cli_cli-developer-commands) 并使用具有集群管理员权限的用户凭证 [登录](https://docs.redhat.com/en/documentation/openshift_container_platform/4.11/html/cli_tools/openshift-cli-oc#cli-logging-in_cli-developer-commands)

* 安装 [Helm CLI](https://helm.sh/docs/intro/install/)

* 安装 [cURL](https://curl.se/)，通过本地端口转发验证网关

## 创建 OpenShift 项目和服务帐户[​](#创建-openshift-项目和服务帐户 "创建 OpenShift 项目和服务帐户的直接链接")

使用具有集群管理员权限的用户帐户登录 OpenShift CLI：

```
oc login <cluster-url> --username <username> --password <password>
```

为 APISIX 创建一个 OpenShift 项目：

```
oc new-project apisix
```

将默认项目切换到 `apisix`：

```
oc project apisix
```

为 APISIX 部署创建服务帐户 `apisix-sa`：

```
oc create sa apisix-sa
```

将 [安全上下文约束 (SCC)](https://docs.openshift.com/container-platform/4.16/authentication/managing-security-context-constraints.html) `nonroot-v2` 添加到服务帐户：

```
oc adm policy add-scc-to-user nonroot-v2 -z apisix-sa
```

## 使用 Helm 安装[​](#使用-helm-安装 "使用 Helm 安装的直接链接")

添加 APISIX Helm 仓库并更新：

```
helm repo add apisix https://apache.github.io/apisix-helm-chart

helm repo update
```

使用发布版本镜像安装 APISIX Helm chart：

```
helm install apisix apisix/apisix \

  --version 2.18.3 \

  --set image.tag=3.20.0-ubuntu \

  --set service.type=NodePort \

  --set etcd.podSecurityContext.enabled=false \

  --set etcd.containerSecurityContext.enabled=false \

  --set serviceAccount.name=apisix-sa
```

❶ 禁用 etcd 的 `podSecurityContext` 和 `containerSecurityContext` 以避免遇到 [与 SCC 相关的问题](https://github.com/bitnami/charts/issues/12215)。

❷ 使用服务帐户 `apisix-sa` 进行部署，以授予 APISIX 所需的权限。

如果成功，你应该看到类似以下的响应：

```
NAME: apisix

LAST DEPLOYED: Wed May 24 07:56:25 2023

NAMESPACE: apisix

STATUS: deployed
```

## 验证安装[​](#验证安装 "验证安装的直接链接")

检查 pod 状态以确保所有 pod 都已启动并正在运行：

```
oc get pod
```

响应应类似于以下内容，所有 pod 均为 `Running`：

```
NAME                      READY   STATUS    RESTARTS   AGE

apisix-5899557df4-5wgcn   1/1     Running   0          6m33s

apisix-etcd-0             1/1     Running   0          6m33s

apisix-etcd-1             1/1     Running   0          6m33s

apisix-etcd-2             1/1     Running   0          6m33s
```

将网关 Service 的 HTTP 端口转发到本地计算机：

```
oc port-forward service/apisix-gateway 9080:80
```

保持端口转发运行。在另一个终端中向 APISIX 发送请求：

```
curl -sI "http://127.0.0.1:9080" | grep Server
```

你应该在响应中看到已配置的 APISIX 版本：

```
Server: APISIX/3.20.0
```

你现在已成功在 ROSA 上安装 APISIX。
