@@ -144,7 +144,7 @@ Examples (with an application's base name `myapp`):
The Kubernetes template supports three techniques to deploy your code:
1. script-based deployment,
2. template-based deployment using raw Kubernetes manifests (with variables substitution),
2. template-based deployment using raw Kubernetes manifests (with [variables substitution](#variables-substitution-mechanism)),
3. template-based deployment using [Kustomization files](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/).
#### 1: script-based deployment
@@ -167,7 +167,7 @@ in your project structure, and let the GitLab CI template [`kubectl apply`](http
The template processes the following steps:
1. _optionally_ executes the `k8s-pre-apply.sh` script in your project to perform specific environment pre-initialization (for e.g. create required services),
2. looks for your Kubernetes deployment file, performs [variables substitution](#using-variables) and [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) it,
2. looks for your Kubernetes deployment file, performs [variables substitution](#variables-substitution-mechanism) and [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) it,
1. look for a specific `deployment-$environment_type.yml` in your project (e.g. `deployment-staging.yml` for staging environment),
2. fallbacks to default `deployment.yml`.
3. _optionally_ executes the `k8s-post-apply.sh` script in your project to perform specific environment post-initialization stuff,
@@ -202,7 +202,7 @@ After deployment (either script-based or template-based), the GitLab CI template
The Kubernetes template supports three techniques to destroy an environment (actually only review environments):
1. script-based deployment,
2. template-based deployment using raw Kubernetes manifests (with variables substitution),
2. template-based deployment using raw Kubernetes manifests (with [variables substitution](#variables-substitution-mechanism)),
3. template-based deployment using [Kustomization files](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/).
#### 1: script-based cleanup
@@ -282,20 +282,26 @@ by using available environment variables:
3. any [custom variable](https://docs.gitlab.com/ee/ci/variables/#for-a-project)
(ex: `${SECRET_TOKEN}` that you have set in your project CI/CD variables)
While your scripts may simply use any of those variables, your Kubernetes and Kustomize resources can use **variable substitution**
with the syntax `${VARIABLE_NAME}`.
Each of those patterns will be dynamically replaced in your resources by the template right before using it.
#### Variables substitution mechanism
You can prevent any line from being processed by appending `# nosubst` at the end of the line.
For instance in the following example, `${REMOTE_SERVICE_NAME}` won't be replaced by its environment value during GitLab job execution:
While your scripts may freely use any of the available variables, your Kubernetes and Kustomize
resources can use a **variables substitution** mechanism implemented by the template:
- Using the syntax `${VARIABLE_NAME}` or `%{VARIABLE_NAME}`.\
:warning: Curly braces (`{}`) are mandatory in the expression (`$VARIABLE_NAME` won't be processed).
- Each of those expressions will be **dynamically expanded** in your resource files with the variable value, right before being used.
- Variable substitution expressions **must be contained in double-quoted strings**.
The substitution implementation takes care of escaping characters that need to be (double quote `"`, backslash `\`, tab `\t`, carriage return `\n` and line feed `\r`).
- Variable substitution can be prevented by appending `# nosubst` at the end of any line.\
Ex:
```yaml
apiVersion:v1
kind:ConfigMap
metadata:
# ${environment_name} will be expanded
labels:
app:${APPLICATION_NAME}
name:${APPLICATION_NAME}
app:"${environment_name}"
name:"${environment_name}"
data:
application.yml:|
remote:
@@ -303,21 +309,6 @@ data:
name: '${REMOTE_SERVICE_NAME}' # nosubst
```
> :warning: In order to be properly replaced, curly braces are mandatory (ex: `${MYVAR}` and not `$MYVAR`).
> Moreover, multiline variables must be surrounded by **double quotes** (`"`).
>
> Example:
>
> ```yaml
> [...]
> containers:
> - name: restaurant-app
> env:
> # multiline variable
> - name: MENU
> value: "${APP_MENU}"
> ```
### Environments URL management
The K8S template supports two ways of providing your environments url: