Skip to content

Commit

Permalink
Merge pull request #154 from vgjm/dev
Browse files Browse the repository at this point in the history
feat: translate config-deployment-syntax.md
  • Loading branch information
anurnomeru authored Dec 13, 2021
2 parents 97cd87f + 8e91a1c commit 2f20671
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 85 deletions.
49 changes: 23 additions & 26 deletions docs/config/config-deployment-advance.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@ import useBaseUrl from '@docusaurus/useBaseUrl';

******

# Dep 组件与其他配置方式的支持
# Support for Dep components and other configuration methods

Nocalhost 的开发配置支持多种开发方式,如 ConfigMapAnnotations 等。实际上,这些配置方式**同样适用于**部署配置。但有些功能是需要配合 K8s WebHook 功能来实现,在 Nocalhost 中,是由一个叫做 `Nocalhost-Dep` 的组件来承担这个角色,`Nocalhost Server` 将自动为你部署这个组件,如果你没有使用 `Nocalhost Server`,那么则需要额外进行 `Nocalhost Dep` 的部署。
Nocalhost's development configuration supports multiple developing ways, such as ConfigMap, Annotations, etc. In fact, these configuration methods ** also suit for ** deployment configuration. But some functions need to be implemented through the K8s adminssion WebHook. In Nocalhost, a component called `Nocalhost-Dep` plays this role, and `Nocalhost Server` will automatically deploy this component for you. if you do not use `Nocalhost Server`, then additional deployment of `Nocalhost Dep` is required.

<br/>

:::info

[Nocalhost 提供了哪些部署配置?](config-deployment-spec.md) 中介绍了哪些部署配置需要额外部署 `Nocalhost Dep` 来进行支持。
[What deployment configurations does Nocalhost provide?](config-deployment-spec.md) introduces which deployment configurations require additional deployment of `Nocalhost Dep`.

:::

<br/>

******

## 使用 ConfigMap 配置部署配置
## Using ConfigMap to make deployment configuration

[部署配置入门 ——— Nocalhost 基础部署配置](config-deployment-quickstart.md) 提到了如何配置一个简单的部署配置。结合 [Nocalhost 支持哪些配置方式 —— 将配置放置在 configmap](configure-en.md#将配置放置在-configmap-中),我们可以得到 ConfigMap 部署配置:
To make a simple deployment configuration is mentioned in [Introduction to Deployment Configuration --- Nocalhost Basic Deployment Configuration](config-deployment-quickstart.md). Combining with [What configuration methods are supported by Nocalhost-place the configuration in configmap](configure-en.md#configuration-in-configmap), we can get the configuration:

我们为此准备了一个体验项目,它将自动部署 `Nocalhost Dep`,并且使用 ConfigMap 的形式进行部署配置的配置。
We have prepared an demo for this, which will automatically deploy `Nocalhost Dep`, and use the way of ConfigMap to make the deployment configuration.


:::tip 使用下列命令来获取并查看此项目(体验该 Chart 包需要 ClusterAdmin 级别的权限)
:::tip Using the following commands to try out this demo (trying the Chart package requires ClusterAdmin)

```shell
git clone https://github.com/nocalhost/bookinfo && git checkout config/example
Expand All @@ -45,17 +44,15 @@ git clone https://github.com/nocalhost/bookinfo && git checkout config/example

<br/>


然后再使用 Helm 来进行安装:
Then use Helm to install:

```shell
helm dep build ./charts/bookinfo && helm install bookinfo ./charts/bookinfo
```

<br/>


部署配置的内容本身这里不做赘述,我们来看看 `charts/bookinfo/templates/nocalhost-app-config.yaml`
The content of the deployment configuration itself will not be repeated here. let's take a look at `charts/bookinfo/templates/nocalhost-app-config.yaml`.

```yaml
apiVersion: v1
Expand All @@ -77,7 +74,7 @@ data:
:::danger
这个 ConfigMap 需要最先被提交的 Api Server,如在 Helm 的应用场景下,它应该被声明为 `pre-install`
This ConfigMap requires to apply to Api Server first. For example, in the Helm application scenario, it should be declared as `pre-install`.

```yaml
annotations:
Expand All @@ -88,7 +85,7 @@ data:

<br/>

它引入了 `.Values.nocalhost.config.path` 来渲染部署配置的主体内容。配置实际上声明在 `./charts/bookinfo/example/config-from-cm/nocalhost-full-config.yaml` 中,它是一个标准的 Nocalhost 部署配置,没有做额外的改造:
It introduces `.Values.nocalhost.config.path` to render the main body of the deployment configuration. The configuration is actually declared in `./charts/bookinfo/example/config-from-cm/nocalhost-full-config.yaml`, which is a standard Nocalhost deployment configuration without any additional modification:

```yaml
application:
Expand Down Expand Up @@ -154,21 +151,21 @@ application:

******

## 使用 Annotations 配置部署配置
## Using Annotations to make the deployment configuration

使用方式与 [Nocalhost 支持哪些配置方式 —— 将配置放置在 annotations 中](configure-en.md#将配置放置在-annotations-中) 完全一致。
The method of usage is exactly the same as [Which configuration methods Nocalhost supports-place the configuration in annotations](configure-en.md#configuration-in-annotations).

:::danger 额外注意
:::danger Extra attention

由于 Annotations 紧跟工作负载,所以不支持应用级别的一些配置,仅支持 `application.services` 下的配置。
Since Annotations closely follow the workload, some configurations at the application level are not supported. Only the configurations under `application.services` is supported.

:::

<br/>

同样使用上述这个体验项目:
Again, use the same demo project:

:::tip 使用下列命令来获取并查看此项目(体验该 Chart 包需要 ClusterAdmin 级别的权限)
:::tip Use the following commands to get and try out this project (trying the Chart package requires ClusterAdmin)

```shell
git clone https://github.com/nocalhost/bookinfo && git checkout config/example
Expand All @@ -179,15 +176,15 @@ git clone https://github.com/nocalhost/bookinfo && git checkout config/example
<br/>


然后再使用 Helm 来进行安装:
Then use Helm to install:

```shell
helm dep build ./charts/bookinfo && helm install bookinfo ./charts/bookinfo -f ./charts/bookinfo/values-annotation-config.yaml
```

<br/>

我们指定了 `values-annotation-config.yaml` 作为 Values.yaml,里面指定了将本地配置文件渲染到工作负载的 Annotations 中,以 `./charts/bookinfo/templates/microservice-details.yaml` 为例:
We specified `values-annotation-config.yaml` as Values.yaml, which specifies the rendering of the local configuration file to the Annotations of the workload. Take `./charts/bookinfo/templates/microservice-details.yaml` as an example:

```yaml
apiVersion: apps/v1
Expand All @@ -205,7 +202,7 @@ metadata:

<br/>

Helm 会将 `.Values.nocalhost.annotations.path.details` 所配置路径渲染到 yaml 中,内容如下,即 Values 中指定的 `./charts/bookinfo/example/config-from-annotations/details.yaml`
Helm will render the path configured by `.Values.nocalhost.annotations.path.details` into yaml, whose content is as follows, that is, `./charts/bookinfo/example/config-from-annotations/details.yaml` specified in Values :

```yaml
containers:
Expand All @@ -219,12 +216,12 @@ containers:

******

## 如何部署 `Nocalhost Dep`
## How to deploy `Nocalhost Dep`

我们推荐使用 `Nocalhost Server` 来获得 `Nocalhost Dep` 的全部功能。
We recommend using `Nocalhost Server` to get all the functions of `Nocalhost Dep`.

:::danger

COMING SOON

:::
:::
100 changes: 63 additions & 37 deletions docs/config/config-deployment-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import useBaseUrl from '@docusaurus/useBaseUrl';

******

# Nocalhost 提供了哪些部署配置?
# What deployment configurations does Nocalhost provide?

:::danger 部分配置需额外组件
:::danger Some configurations require additional components


部署配置的部分功能依赖于 **Nocalhost-Dep 组件**,如果你使用 Nocalhost Server,我们会自动帮你处理这个组件的安装,否则需要进行额外的安装。
Some functions of the deployment configuration rely on the **Nocalhost-Dep component**. If you use Nocalhost Server, we will automatically install this component for you. Otherwise an additional installation is required.

如果没有安装 **Nocalhost-Dep 组件**,部分功能将受限,文章中将会标记出那些需要借助 ** Nocalhost-Dep ** 才能实现的功能。
If the **Nocalhost-Dep component** is not installed, some functions will be restricted. This article will mark those functions that need **Nocalhost-Dep**.

:::

## 启动顺序依赖控制 ([组件依赖](#danger))
范例:
## Startup dependency control ([component dependency](#danger))
Example:
```yaml
application:
name: example
Expand All @@ -45,18 +45,20 @@ application:
- "job-name=init-job"
```
当某项资源在部署配置中声明了 `dependLabelSelector` 以后, `pods` 数组中的字符代表要等待的 pods 的 labels,格式为键值对。`jobs` 数组中的字符代表要等待的 jods 的 labels,格式为键值对。
When a resource declares `dependLabelSelector` in the deployment configuration, the characters in the `pods` array represent the labels of the pods to be waited for. The format is key-value pairs. The characters in the `jobs` array represent the labels of the jods to be waited for. The format is also key-value pairs.

`pods` `jobs` 都为可选项。实际部署过程中,它会为指定的工作负载生成一个 `initContinaer`,等待所有匹配 label 的 pods 状态为 `Ready`,等待所有匹配 label 的 jobs 状态为 `Succeeded`
Both `pods` and `jobs` are optional. When you actually deploy your application, it will generate an `initContainer` for the specified workload, wait for the status of all pods matching the label to be `Ready`, and wait for the status of all jobs matching the label to be `Succeeded`.

<br/>

******

## 环境变量注入 ([组件依赖](#danger))
## Injecting Environment variable ([Component dependency](#danger))

### Injecting Global variable

Example:

### 全局变量注入
范例:
```yaml
application:
name: example
Expand All @@ -76,24 +78,33 @@ application:
```

全局变量注入需要声明在 `application` 这一级,在部署时,它将往所有部署的 `Deployment`、`DaemonSet`、`ReplicaSet`、`StatefulSet`、`Job`、`CronJob` 中注入对应的环境变量。
Injecting global variables needs to be declared at the level of `application`. During the deployment, it will inject the corresponding environment variables into all deployed `Deployment`, `DaemonSet`, `ReplicaSet`, `StatefulSet`, `Job`, and `CronJob`.

:::tip Injecting variables supports two kinds syntax, which can be mixed

- The first one is to declare key-value pairs directly
- The second is to declare an env file relative to `config.yaml`, the content is line-by-line `Key=Value`:


:::tip 变量注入支持两种写法,可以混搭
- 第一种是直接声明键值对
- 第二种是声明一个相对于 `config.yaml` 的 env 文件,内容为逐行的 `Key=Value`:
```dotenv
DEBUG=true
DOMAIN=nocalhost.dev
```

:::

其中,`env` 的优先级高于 `envFrom`
The priority of `env` is higher than that of `envFrom`

<br/>

### 容器级变量注入
范例:
### Injecting variables at the level of container

Example:

```yaml
application:
name: example
manifestType: rawManifestGit
Expand All @@ -116,16 +127,19 @@ application:
envFile:
- path: relpath/to/env/file
##### end
```

容器级的变量注入声明在 `application.services[*].containers[*].install` 中,表明在部署时,往对应的容器中注入对应变量。`env` `envFrom` 的规则与应用级一致。
The container-level variable injection is declared in `application.services[*].containers[*].install`, indicating that the corresponding variables are injected into the corresponding container during deployment. The rules of `env` and `envFrom` are in line with the application level's.

<br/>

******

## 安装后自动端口转发
范例:
## Automatic port forwarding after installation

Example:

```yaml
application:
name: example
Expand All @@ -144,18 +158,21 @@ application:
- 5005:5005
- 3306:3306
##### end
```

配置规则与容器及的变量注入声明类似,需要配置在 `application.services[*].containers[*].install` 中。
The configuration rules are similar to the container and variable injection declarations, and need to be configured in `application.services[*].containers[*].install`.

安装后的端口转发顾名思义,在应用安装完毕,可以自动为某些服务做端口转发到本地,如常用的数据库、MQ 等端口,适合在安装完毕后自动转发,配置的规则。端口转发的规则与 K8s 一致,即 `本地端口:容器端口`
The port forwarding after installation is as it's name implies. After the application is installed, it can automatically forward port to the local for some services. For instance, database, MQ and other commonly used services' ports are suitable for automatic forwarding and configuration rules after installation. The port forwarding rules are consistent with K8s, namely `local port: container port`.

<br/>

******

## Hook
范例:

Example:

```yaml
application:
name: example
Expand Down Expand Up @@ -184,34 +201,40 @@ application:
- path: manifest/templates/hook/post-delete.yaml
weight: "1"
##### end
```


Nocalhost 支持在应用的生命周期注入各种 Hook,**Hook 目前只支持 Job**,其中 `path` 为**相对于主目录**的 RawManifest,必须是 Job 类型,`weight` 为权重,权重低的先执行。
Nocalhost supports injecting various hooks in the life cycle of the application. **Hooks currently only support Job**, where `path` is the RawManifest **relative to the home directory**, which must be the job type. `weight` is the weight. The lower ones are executed first.

<br/>

:::danger Hook的限制
Hook 与 Helm 的 Hook 类似,Hook 本身是为了弥补非 Helm 应用的不足,所以**Helm 类型应用无法配置 Hook(你可以直接使用 Helm 的 Hook)**。
:::danger The limits on the Hook

Hook is similar to Helm's Hook. Hook itself is to make up for the shortcomings of non-Helm applications, so ** Helm-type applications cannot configure Hook (You can use Helm's Hook directly)**.

:::

<br/>

:::info Hook的解释
- `onPreInstall` 发生在应用部署之前,例如执行集群、数据库之类的的一些初始化操作。会在 Job 状态为 `Successed` 后,才开始真正执行部署,如果失败,则安装终止。
- `onPostInstall` 发生在应用部署之后,当所有资源都提交到 K8s Api Server,会执行此 Job,状态为 `Successed` 后,部署成功。否则将回滚,执行卸载操作。
:::info The explanation of Hook

- `onPreInstall` occurs before the employment of the application, including performing some initialization operations such as clusters and databases. The deployment will start after the job status is `Successed`. If it fails, the installation will be terminated.
- `onPostInstall` occurs after the application is deployed. When all resources are submitted to the K8s Api Server, this job will be executed. After the status is `Successed`, the deployment is successful. Otherwise, it will roll back and perform the uninstall operation.

<br/>

依次类推,UpgradeHook 和 DeleteHook 不同的是,它们在执行失败后都不会进行回滚,仅提示失败。
By analogy, the Upgrade Hook and Delete Hook will not roll back after the execution fails, and only prompt failure.
:::

<br/>

******

## HelmValues 的定制
范例:
## The customization of the HelmValues

Example:

```yaml
application:
name: example
Expand All @@ -231,11 +254,14 @@ application:
deploy:
example: {{ Release.Name }}
##### end
```

<br/>

:::tip HelmValues 支持两种写法
- 第一种写法仅支持纯字符串,优先级更高。
- 第二种写法与 `values.yaml` 别无二致,可穿插 Helm 语法。
:::
:::tip HelmValues supports two kinds of syntax

- The first syntax only supports pure strings and has a higher priority.
- The second syntax is the same as `values.yaml` and can be interspersed with Helm syntax.

:::
Loading

0 comments on commit 2f20671

Please sign in to comment.