> For the complete documentation index, see [llms.txt](https://appsmithcns-organization.gitbook.io/pageplug-wen-dang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://appsmithcns-organization.gitbook.io/pageplug-wen-dang/ben-di-bu-shu/kubernetes.md).

# Kubernetes

我们提供一个安装脚本，可帮助你配置 PagePlug 并在 Kubernetes 集群上部署你的应用程序

## 使用 Helm Charts 安装 PagePlug

此图表使用 Helm 包管理器在 Kubernetes 集群上引导 PagePlug 部署。

### 先决条件

* 安装 Helm 包管理器
* 确保已安装并配置 `kubectl`以连接到集群。
  * 安装 kubectl&#x20;
  * Minikube：设置 kubectl
  * Google Cloud Kubernetes ：为 kubectl 配置群集访问
  * AWS EKS : 为亚马逊 EKS 创建一个 kubeconfig
  * Microk8s : 使用 kubectl
* 请确保群集上运行默认存储类，请按照以下准则之一启用默认存储类
  * Minikube：启用插件默认存储类
  * Google Cloud Kubernetes ：在 GKE 上设置默认存储类
  * AWS EKS : 创建默认存储类
  * Microk8s : 启用存储
* 默认情况下，应在群集上启用 Kubernetes NGINX 入口控制器，请确保为群集安装正确版本
  * Minikube：使用 NGINX 入口控制器在 Minikube 上设置入口
  * Google Cloud Kubernetes ：在 Google Cloud Kubernetes 引擎上使用 NGINX 控制器入口
  * AWS EKS : 安装适用于 AWS EKS 的 NGINX 控制器
  * Microk8s : 附加：入口

{% hint style="warning" %}
注意：在默认情况下，入口控制器不会启动数据压缩，你可以按照 NGINX 入口控制器压缩部分。
{% endhint %}

### 安装图表

1. 使用 Helm 将 pageplug 添加到你的储存库中。

```
helm repo add appsmith https://helm.appsmith.com

helm repo update
```

2\.  使用 pageplug 版本安装图表。

```
helm install appsmith/appsmith --generate-name
```

该命令以默认配置在 Kubernetes 集群上部署 pageplug 应用程序。这参数部分列出了安装过程中的可配置参数。

### 卸载图表

#### 全局参数

| 名字                         | 描述             | Value                      |
| -------------------------- | -------------- | -------------------------- |
| `global.namespaceOverride` | 重写图表部署的资源的命名空间 | <p><code>""</code><br></p> |
| `global.storageClass`      | 持久卷的全局存储类      | `""`                       |

#### 常用参数

| 名字                  | 描述                          | Value        |
| ------------------- | --------------------------- | ------------ |
| `fullnameOverride`  | 要完全覆盖`appsmith.name` 模版的字符串 | `""`         |
| `containerName`     | 指定在 Pod 中运行的容器的名称           | `"appsmith"` |
| `commonLabels`      | 要添加到所有已部署对象的标签              | `{}`         |
| `commonAnnotations` | 要添加到所有已部署对象的批注              | `{}`         |

#### PagePlug 镜像参数

| 名字                 | 描述                  | Value                      |
| ------------------ | ------------------- | -------------------------- |
| `image.registry`   | pageplug 镜像registry | `index.docker.io`          |
| `image.repository` | pageplug 镜像存储库      | `appsmith/appsmith-editor` |
| `image.tag`        | pageplug 镜像标签       | `latest`                   |
| `image.pullPolicy` | pageplug 镜像拉取策略     | `IfNotPresent`             |

#### 应用软件部署参数

| 名字                   | 描述                  | Value           |
| -------------------- | ------------------- | --------------- |
| `strategyType`       | pageplug 部署策略类型     | `RollingUpdate` |
| `schedulerName`      | 备用调度程序              | `""`            |
| `podAnnotations`     | pageplug pod 的注解    | `{}`            |
| `podSecurityContext` | pageplug pods 安全上下文 | `{}`            |
| `securityContext`    | 设置安全上下文             | `{}`            |
| `resources.limits`   | pageplug 容器的资源限制    | `{}`            |
| `resources.requests` | pageplug 容器请求的资源    | `{}`            |
| `nodeSelector`       | pod 分配的节点标签         | `{}`            |
| `tolerations`        | pod 分配的容差           | `[]`            |
| `affinity`           | 亲和 fod pod 分配       | `{}`            |

#### pageplug 命名空间参数

| 名字                 | 描述               | Value  |
| ------------------ | ---------------- | ------ |
| `namespace.create` | 启用`Namespace`的创建 | `true` |

#### pageplug 服务账户参数

| 名字                           | 描述                                                       | Value                        |
| ---------------------------- | -------------------------------------------------------- | ---------------------------- |
| `serviceAccount.create`      | 为 pageplug pod启用创建 `ServiceAccoun`                       | <p><code>true</code><br></p> |
| `serviceAccount.name`        | 创建的名称`ServiceAccount`。如果未设置，则使用 appsmith.fullname 模板生成名称 | `""`                         |
| `serviceAccount.annotations` | 其他服务账号注释                                                 | `{}`                         |

#### 流量暴露参数

| 名字                                 | 描述                                | Value       |
| ---------------------------------- | --------------------------------- | ----------- |
| `service.type`                     | Appsmith 服务类型                     | `ClusterIP` |
| `service.port`                     | Appsmith服务端口                      | `80`        |
| `service.portName`                 | Appsmith 服务端口名称                   | `appsmith`  |
| `service.nodePort`                 | Appsmith 服务节点端口要暴露要暴露             | `8000`      |
| `service.clusterIP`                | Appsmith服务集群                      | `""`        |
| `service.loadBalancerIP`           | Appsmith 服务负载均衡器 IP               | `""`        |
| `service.loadBalancerSourceRanges` | Appsmith 服务负载均衡器来源                | `[]`        |
| `service.annotations`              | Appsmith 服务的附加自定义注释               | `{}`        |
| `ingress.enabled`                  | 为 Appsmith 启用入口记录生成               | `false`     |
| `ingress.hosts`                    | 要被入口记录覆盖的主机数组                     | `[]`        |
| `ingress.tls`                      | 为参数中定义的主机启用 TLS 配置`ingress.hosts` | `false`     |
| `ingress.secrets`                  | 自定义 TLS 证书作为机密                    | `[]`        |
| `ingress.certManager`              | 启用入口以使用 Cert Manager 提供的 TLS 证书   | `false`     |
| `ingress.certManagerTls`           | 指定证书管理器创建的 TLS 机密资源               | `[]`        |
| `ingress.className`                | 配置在入口资源中使用的入口类                    | `""`        |

#### 持久性参数

| 姓名                                  | 描述                                | Value                      |
| ----------------------------------- | --------------------------------- | -------------------------- |
| `persistence.enabled`               | 使用 Persistent Volume Claims 启用持久性 | `true`                     |
| `persistence.storageClass`          | 持久卷存储类                            | `""`                       |
| `persistence.annotations`           | PVC 的附加自定义注释                      | `{}`                       |
| `persistence.localStorage`          | 使用本地存储启用持久卷                       | `false`                    |
| `persistence.storagePath`           | 本地存储路径                            | `/tmp/hostpath_pv`         |
| `persistence.localCluster`          | 本地运行集群提供存储空间                      | `[minikube]`               |
| `persistence.accessModes`           | 持久卷访问模式                           | `[ReadWriteOnce]`          |
| `persistence.size`                  | 持久卷大小                             | `10Gi`                     |
| `storageClass.enabled`              | 启用存储类配置                           | `false`                    |
| `storageClass.defaultClass`         | 创建默认存储类                           | `false`                    |
| `storageClass.bindingMode`          | 使用存储类的持久卷声明的绑定模式                  | `Immediate`                |
| `storageClass.allowVolumeExpansion` | 允许使用存储类扩展持久卷声明                    | `true`                     |
| `storageClass.reclaimPolicy`        | 配置动态创建的持久卷的保留                     | `Delete`                   |
| `storageClass.provisioner`          | 存储类供应商                            | <p><code>""</code><br></p> |
| `storageClass.annotations`          | 其他存储类注释                           | `{}`                       |
| `storageClass.mountOptions`         | 持久卷使用的挂载选项                        | `{}`                       |
| `storageClass.parameters`           | 存储类参数                             | `{}`                       |

#### 自动更新图表的镜像

| 名字                     | 描述                  | Value         |
| ---------------------- | ------------------- | ------------- |
| `autoupdate.enabled`   | 启用自动更新 Helm 图表的镜像   | `true`        |
| `autoupdate.scheduler` | 安排时间运行 cronjob以更新映像 | `"0 * * * *"` |

使用`--set key=value[,key=value]`参数指定每个参数，以帮助安装。例如：

```
helm install \
--set persistence.storageClass=appsmith-pv \
  stable-appsmith/appsmith --generate-name
```

***提示**：你可以使用默认* [*<mark style="color:orange;">values.yaml</mark>*](https://github.com/appsmithorg/appsmith/blob/release/deploy/helm/values.yaml) *作为以这种方式部署的起点。*

#### pageplug 配置

要更改pageplug的配置，你可以更新`values.yaml`文件（下面列出了可用的配置）。

| 名字                                                       | Value |
| -------------------------------------------------------- | ----- |
| `applicationConfig.APPSMITH_OAUTH2_GOOGLE_CLIENT_ID`     | `""`  |
| `applicationConfig.APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET` | `""`  |
| `applicationConfig.APPSMITH_OAUTH2_GITHUB_CLIENT_ID`     | `""`  |
| `applicationConfig.APPSMITH_OAUTH2_GITHUB_CLIENT_SECRET` | `""`  |
| `applicationConfig.APPSMITH_CLIENT_LOG_LEVEL`            | `""`  |
| `applicationConfig.APPSMITH_GOOGLE_MAPS_API_KEY`         | `""`  |
| `applicationConfig.APPSMITH_MAIL_ENABLED`                | `""`  |
| `applicationConfig.APPSMITH_MAIL_HOST`                   | `""`  |
| `applicationConfig.APPSMITH_MAIL_PORT`                   | `""`  |
| `applicationConfig.APPSMITH_MAIL_USERNAME`               | `""`  |
| `applicationConfig.APPSMITH_MAIL_PASSWORD`               | `""`  |
| `applicationConfig.APPSMITH_MAIL_FROM`                   | `""`  |
| `applicationConfig.APPSMITH_REPLY_TO`                    | `""`  |
| `applicationConfig.APPSMITH_MAIL_SMTP_AUTH`              | `""`  |
| `applicationConfig.APPSMITH_MAIL_SMTP_TLS_ENABLED`       | `""`  |
| `applicationConfig.APPSMITH_DISABLE_TELEMETRY`           | `""`  |
| `applicationConfig.APPSMITH_RECAPTCHA_SITE_KEY`          | `""`  |
| `applicationConfig.APPSMITH_RECAPTCHA_SECRET_KEY`        | `""`  |
| `applicationConfig.APPSMITH_RECAPTCHA_ENABLED`           | `""`  |
| `applicationConfig.APPSMITH_MONGODB_URI`                 | `""`  |
| `applicationConfig.APPSMITH_REDIS_URL`                   | `""`  |
| `applicationConfig.APPSMITH_ENCRYPTION_PASSWORD`         | `""`  |
| `applicationConfig.APPSMITH_ENCRYPTION_SALT`             | `""`  |
| `applicationConfig.APPSMITH_CUSTOM_DOMAIN`               | `""`  |

例如，若想要更改加密 salt 配置，可以运行以下命令：

```
helm install \
--set applicationConfig.APPSMITH_ENCRYPTION_SALT=123 \
  stable-appsmith/appsmith --generate-name
```

### 暴露 pageplug

* 如果你希望通过互联网想全世界发布你的 pageplug ，则需要先设置入口控制器。请参阅“Kubernetes NGINX 入口控制器”部分先决条件。
* 如果你尚未安装 Helm 图表，则可以运行以下命令来安装它，并公开 pageplug：

```
helm install appsmith/appsmith --generate-name \
  --set ingress.enabled=true \
  --set ingress.annotations."kubernetes\.io/ingress\.class"=nginx \
  --set service.type=ClusterIP
```

* 如果你已安装 PagePlug Helm 图表，请运行`helm upgrade`命令以升级现有安装

```
helm upgrade --set ingress.enabled=true appsmith appsmith/appsmith

# Or this command if you are using values.yaml file
helm upgrade --values values.yaml appsmith appsmith/appsmith
```

### 更新 pageplug

#### 自动更新

1. 在默认的 pageplug Helm 安装中，自动更新处于禁用状态（推荐）。你可以选择通过以下方式为 pageplug Helm 部署启用自动更新：

* 如果在`values.yaml` 文件中将自动更新`autoupdate.enabled`设置为`true`（如果使用值文件）

```
 helm upgrade --values values.yaml appsmith appsmith/appsmith
```

* 通过将参数`--set autoupdate.enabled=true` 传递给 Helm 安装/升级命令。

```
  helm install appsmith/appsmith --generate-name \
    --set ingress.enabled=true \
    --set ingress.annotations."kubernetes\.io/ingress\.class"=nginx \
    --set service.type=ClusterIP \
    --set autoupdate.enabled=true
```

#### 手动更新

* 若要手动将 pageplug 容器镜像更新到最新版本，请运行以下命令：`kubectl rollout restart statefulset appsmith`

### Nginx 入口控制器压缩 （Gzip）

在默认安装中，Nginx 入口控制器将不配置数据压缩，请按照以下步骤启动它。

* 使用以下命令编辑`ingress-nginx-controller`的`configMap`

```
kubectl edit configmap -n ingress-nginx ingress-nginx-controller
```

* 将以下内容添加到数据部分。

```
data: # ADD IF NOT PRESENT
  use-gzip: "true" # ENABLE GZIP COMPRESSION
  gzip-types: "*" # SPECIFY MIME TYPES TO COMPRESS ("*" FOR ALL) 
```

{% hint style="warning" %}
Nginx控制器将在保存（:wq!）上述修改后自动更新。
{% endhint %}
