debian-mirror-gitlab/doc/user/project/clusters/index.md

460 lines
21 KiB
Markdown
Raw Normal View History

2020-05-24 23:13:21 +05:30
---
stage: Monitor
2021-01-03 14:25:43 +05:30
group: Health
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-05-24 23:13:21 +05:30
---
2021-03-11 19:13:27 +05:30
# Kubernetes clusters **(FREE)**
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/35954) in GitLab 10.1 for projects.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/34758) in
2019-10-12 21:52:04 +05:30
> GitLab 11.6 for [groups](../../group/clusters/index.md).
2020-06-23 00:09:42 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/39840) in
2019-10-12 21:52:04 +05:30
> GitLab 11.11 for [instances](../../instance/clusters/index.md).
2018-03-17 18:26:18 +05:30
2019-10-12 21:52:04 +05:30
Using the GitLab project Kubernetes integration, you can:
- Use [Review Apps](../../../ci/review_apps/index.md).
2020-04-08 14:13:33 +05:30
- Run [pipelines](../../../ci/pipelines/index.md).
2019-10-12 21:52:04 +05:30
- [Deploy](#deploying-to-a-kubernetes-cluster) your applications.
2020-07-28 23:09:34 +05:30
- Detect and [monitor Kubernetes](#monitoring-your-kubernetes-cluster).
2019-10-12 21:52:04 +05:30
- Use it with [Auto DevOps](#auto-devops).
- Use [Web terminals](#web-terminals).
2021-03-08 18:12:59 +05:30
- Use [Deploy Boards](#deploy-boards).
2020-11-24 15:15:51 +05:30
- Use [Canary Deployments](#canary-deployments). **(PREMIUM)**
2021-01-29 00:20:46 +05:30
- Use [deployment variables](#deployment-variables).
- Use [role-based or attribute-based access controls](add_remove_clusters.md#access-controls).
2020-07-28 23:09:34 +05:30
- View [Logs](#viewing-pod-logs).
2019-10-12 21:52:04 +05:30
- Run serverless workloads on [Kubernetes with Knative](serverless/index.md).
2020-07-28 23:09:34 +05:30
Besides integration at the project level, Kubernetes clusters can also be
integrated at the [group level](../../group/clusters/index.md) or
[GitLab instance level](../../instance/clusters/index.md).
2021-01-03 14:25:43 +05:30
To view your project level Kubernetes clusters, navigate to **Operations > Kubernetes**
from your project. On this page, you can [add a new cluster](#adding-and-removing-clusters)
2021-03-11 19:13:27 +05:30
and view information about your existing clusters, such as:
- Nodes count.
- Rough estimates of memory and CPU usage.
2021-01-03 14:25:43 +05:30
2020-07-28 23:09:34 +05:30
## Setting up
2020-05-24 23:13:21 +05:30
### Supported cluster versions
2020-07-28 23:09:34 +05:30
GitLab is committed to support at least two production-ready Kubernetes minor
versions at any given time. We regularly review the versions we support, and
2021-01-29 00:20:46 +05:30
provide a three-month deprecation period before we remove support of a specific
2020-07-28 23:09:34 +05:30
version. The range of supported versions is based on the evaluation of:
2020-05-24 23:13:21 +05:30
- The versions supported by major managed Kubernetes providers.
- The versions [supported by the Kubernetes community](https://kubernetes.io/docs/setup/release/version-skew-policy/#supported-versions).
2021-01-29 00:20:46 +05:30
GitLab supports the following Kubernetes versions, and you can upgrade your
Kubernetes version to any supported version at any time:
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
- 1.19 (support ends on February 22, 2022)
- 1.18 (support ends on November 22, 2021)
- 1.17 (support ends on September 22, 2021)
- 1.16 (support ends on July 22, 2021)
- 1.15 (support ends on May 22, 2021)
2021-01-03 14:25:43 +05:30
- 1.14 (deprecated, support ends on December 22, 2020)
2020-05-24 23:13:21 +05:30
Some GitLab features may support versions outside the range provided here.
2020-07-28 23:09:34 +05:30
### Adding and removing clusters
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
See [Adding and removing Kubernetes clusters](add_remove_clusters.md) for details on how
to:
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
- Create a cluster in Google Cloud Platform (GCP) or Amazon Elastic Kubernetes Service
2021-02-22 17:27:13 +05:30
(EKS) using the GitLab UI.
2020-07-28 23:09:34 +05:30
- Add an integration to an existing cluster from any Kubernetes platform.
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
### Multiple Kubernetes clusters
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
> - Introduced in [GitLab Premium](https://about.gitlab.com/pricing/) 10.3
2021-03-11 19:13:27 +05:30
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35094) to GitLab Free in 13.2.
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
You can associate more than one Kubernetes cluster to your
project. That way you can have different clusters for different environments,
2021-03-11 19:13:27 +05:30
like development, staging, production, and so on.
Add another cluster, like you did the first time, and make sure to
2021-02-22 17:27:13 +05:30
[set an environment scope](#setting-the-environment-scope) that
differentiates the new cluster from the rest.
2019-10-12 21:52:04 +05:30
2020-10-04 03:57:07 +05:30
#### Setting the environment scope
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
When adding more than one Kubernetes cluster to your project, you need to differentiate
them with an environment scope. The environment scope associates clusters with [environments](../../../ci/environments/index.md) similar to how the
2021-03-11 19:13:27 +05:30
[environment-specific variables](../../../ci/variables/README.md#limit-the-environment-scopes-of-cicd-variables) work.
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
The default environment scope is `*`, which means all jobs, regardless of their
2021-02-22 17:27:13 +05:30
environment, use that cluster. Each scope can be used only by a single cluster
in a project, and a validation error occurs if otherwise. Also, jobs that don't
have an environment keyword set can't access any cluster.
2018-03-17 18:26:18 +05:30
2020-07-28 23:09:34 +05:30
For example, let's say the following Kubernetes clusters exist in a project:
2018-03-17 18:26:18 +05:30
2020-07-28 23:09:34 +05:30
| Cluster | Environment scope |
| ----------- | ----------------- |
| Development | `*` |
| Production | `production` |
2019-02-15 15:39:39 +05:30
2020-07-28 23:09:34 +05:30
And the following environments are set in
[`.gitlab-ci.yml`](../../../ci/yaml/README.md):
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
```yaml
stages:
- test
- deploy
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
test:
stage: test
script: sh test
2019-10-12 21:52:04 +05:30
2020-07-28 23:09:34 +05:30
deploy to staging:
stage: deploy
script: make deploy
environment:
name: staging
url: https://staging.example.com/
2020-03-13 15:44:24 +05:30
2020-07-28 23:09:34 +05:30
deploy to production:
stage: deploy
script: make deploy
environment:
name: production
url: https://example.com/
```
2020-03-13 15:44:24 +05:30
2021-02-22 17:27:13 +05:30
The results:
2020-03-13 15:44:24 +05:30
2021-02-22 17:27:13 +05:30
- The Development cluster details are available in the `deploy to staging`
2020-07-28 23:09:34 +05:30
job.
2021-02-22 17:27:13 +05:30
- The production cluster details are available in the `deploy to production`
2020-07-28 23:09:34 +05:30
job.
2021-02-22 17:27:13 +05:30
- No cluster details are available in the `test` job because it doesn't
2020-07-28 23:09:34 +05:30
define any environment.
2020-03-13 15:44:24 +05:30
2020-07-28 23:09:34 +05:30
## Configuring your Kubernetes cluster
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
After [adding a Kubernetes cluster](add_remove_clusters.md) to GitLab, read this section that covers
important considerations for configuring Kubernetes clusters with GitLab.
2019-10-12 21:52:04 +05:30
### Security implications
2018-03-27 19:54:05 +05:30
2021-02-22 17:27:13 +05:30
WARNING:
2018-03-27 19:54:05 +05:30
The whole cluster security is based on a model where [developers](../../permissions.md)
are trusted, so **only trusted users should be allowed to control your clusters**.
The default cluster configuration grants access to a wide set of
functionalities needed to successfully build and deploy a containerized
2019-02-15 15:39:39 +05:30
application. Bear in mind that the same credentials are used for all the
2018-03-27 19:54:05 +05:30
applications running on the cluster.
2019-10-12 21:52:04 +05:30
### GitLab-managed clusters
2019-07-31 22:56:46 +05:30
2020-03-13 15:44:24 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/22011) in GitLab 11.5.
> - Became [optional](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/26565) in GitLab 11.11.
2019-07-31 22:56:46 +05:30
2021-02-22 17:27:13 +05:30
You can choose to allow GitLab to manage your cluster for you. If your cluster
is managed by GitLab, resources for your projects are automatically created. See
the [Access controls](add_remove_clusters.md#access-controls) section for
details about the created resources.
2019-07-31 22:56:46 +05:30
2021-02-22 17:27:13 +05:30
If you choose to manage your own cluster, project-specific resources aren't created
automatically. If you are using [Auto DevOps](../../../topics/autodevops/index.md), you must
explicitly provide the `KUBE_NAMESPACE` [deployment variable](#deployment-variables)
2021-03-11 19:13:27 +05:30
for your deployment jobs to use. Otherwise, a namespace is created for you.
2019-07-31 22:56:46 +05:30
2020-01-01 13:55:28 +05:30
#### Important notes
Note the following with GitLab and clusters:
- If you [install applications](#installing-applications) on your cluster, GitLab will
create the resources required to run these even if you have chosen to manage your own
cluster.
- Be aware that manually managing resources that have been created by GitLab, like
namespaces and service accounts, can cause unexpected errors. If this occurs, try
[clearing the cluster cache](#clearing-the-cluster-cache).
#### Clearing the cluster cache
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/31759) in GitLab 12.6.
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
If you allow GitLab to manage your cluster, GitLab stores a cached
2020-01-01 13:55:28 +05:30
version of the namespaces and service accounts it creates for your projects. If you
modify these resources in your cluster manually, this cache can fall out of sync with
2021-03-11 19:13:27 +05:30
your cluster. This can cause deployment jobs to fail.
2020-01-01 13:55:28 +05:30
To clear the cache:
1. Navigate to your projects **Operations > Kubernetes** page, and select your cluster.
1. Expand the **Advanced settings** section.
1. Click **Clear cluster cache**.
2019-07-31 22:56:46 +05:30
2019-10-12 21:52:04 +05:30
### Base domain
2019-03-02 22:35:43 +05:30
2020-03-13 15:44:24 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/24580) in GitLab 11.8.
2019-03-02 22:35:43 +05:30
2019-07-07 11:18:12 +05:30
You do not need to specify a base domain on cluster settings when using GitLab Serverless. The domain in that case
2021-02-22 17:27:13 +05:30
is specified as part of the Knative installation. See [Installing Applications](#installing-applications).
2019-07-07 11:18:12 +05:30
2021-02-22 17:27:13 +05:30
Specifying a base domain automatically sets `KUBE_INGRESS_BASE_DOMAIN` as an environment variable.
If you are using [Auto DevOps](../../../topics/autodevops/index.md), this domain is used for the different
2019-07-07 11:18:12 +05:30
stages. For example, Auto Review Apps and Auto Deploy.
2021-03-11 19:13:27 +05:30
The domain should have a wildcard DNS configured to the Ingress IP address.
After Ingress has been installed (see [Installing Applications](#installing-applications)),
2019-07-07 11:18:12 +05:30
you can either:
2019-03-02 22:35:43 +05:30
2019-07-07 11:18:12 +05:30
- Create an `A` record that points to the Ingress IP address with your domain provider.
- Enter a wildcard DNS address using a service such as nip.io or xip.io. For example, `192.168.1.1.xip.io`.
2019-03-02 22:35:43 +05:30
2021-03-11 19:13:27 +05:30
To determine the external Ingress IP address, or external Ingress hostname:
- *If the cluster is on GKE*:
1. Click the **Google Kubernetes Engine** link in the **Advanced settings**,
or go directly to the [Google Kubernetes Engine dashboard](https://console.cloud.google.com/kubernetes/).
1. Select the proper project and cluster.
1. Click **Connect**
1. Execute the `gcloud` command in a local terminal or using the **Cloud Shell**.
- *If the cluster is not on GKE*: Follow the specific instructions for your
Kubernetes provider to configure `kubectl` with the right credentials.
The output of the following examples show the external endpoint of your
cluster. This information can then be used to set up DNS entries and forwarding
rules that allow external access to your deployed applications.
Depending an your Ingress, the external IP address can be retrieved in various ways.
This list provides a generic solution, and some GitLab-specific approaches:
- In general, you can list the IP addresses of all load balancers by running:
```shell
kubectl get svc --all-namespaces -o jsonpath='{range.items[?(@.status.loadBalancer.ingress)]}{.status.loadBalancer.ingress[*].ip} '
```
- If you installed Ingress using the **Applications**, run:
```shell
kubectl get service --namespace=gitlab-managed-apps ingress-nginx-ingress-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
```
- Some Kubernetes clusters return a hostname instead, like
[Amazon EKS](https://aws.amazon.com/eks/). For these platforms, run:
```shell
kubectl get service --namespace=gitlab-managed-apps ingress-nginx-ingress-controller -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'
```
If you use EKS, an [Elastic Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/)
is also created, which incurs additional AWS costs.
- Istio/Knative uses a different command. Run:
```shell
kubectl get svc --namespace=istio-system istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip} '
```
If you see a trailing `%` on some Kubernetes versions, do not include it.
2018-03-17 18:26:18 +05:30
## Installing applications
2019-12-26 22:10:19 +05:30
GitLab can install and manage some applications like Helm, GitLab Runner, Ingress,
2020-04-22 19:07:51 +05:30
Prometheus, and so on, in your project-level cluster. For more information on
2019-12-26 22:10:19 +05:30
installing, upgrading, uninstalling, and troubleshooting applications for
your project cluster, see
2019-12-21 20:55:43 +05:30
[GitLab Managed Apps](../../clusters/applications.md).
2019-07-07 11:18:12 +05:30
2020-07-28 23:09:34 +05:30
## Auto DevOps
Auto DevOps automatically detects, builds, tests, deploys, and monitors your
applications.
To make full use of Auto DevOps (Auto Deploy, Auto Review Apps, and
2021-03-11 19:13:27 +05:30
Auto Monitoring) the Kubernetes project integration must be enabled. However,
2021-01-03 14:25:43 +05:30
Kubernetes clusters can be used without Auto DevOps.
2020-07-28 23:09:34 +05:30
2021-03-11 19:13:27 +05:30
[Read more about Auto DevOps](../../../topics/autodevops/index.md).
2020-07-28 23:09:34 +05:30
2019-10-12 21:52:04 +05:30
## Deploying to a Kubernetes cluster
2019-02-15 15:39:39 +05:30
2019-10-12 21:52:04 +05:30
A Kubernetes cluster can be the destination for a deployment job. If
2018-03-17 18:26:18 +05:30
2019-10-12 21:52:04 +05:30
- The cluster is integrated with GitLab, special
[deployment variables](#deployment-variables) are made available to your job
and configuration is not required. You can immediately begin interacting with
the cluster from your jobs using tools such as `kubectl` or `helm`.
2021-02-22 17:27:13 +05:30
- You don't use the GitLab cluster integration, you can still deploy to your
cluster. However, you must configure Kubernetes tools yourself
2021-03-11 19:13:27 +05:30
using [environment variables](../../../ci/variables/README.md#custom-cicd-variables)
2019-10-12 21:52:04 +05:30
before you can interact with the cluster from your jobs.
2018-03-17 18:26:18 +05:30
2019-10-12 21:52:04 +05:30
### Deployment variables
2018-03-17 18:26:18 +05:30
2021-01-29 00:20:46 +05:30
Deployment variables require a valid [Deploy Token](../deploy_tokens/index.md) named
[`gitlab-deploy-token`](../deploy_tokens/index.md#gitlab-deploy-token), and the
following command in your deployment job script, for Kubernetes to access the registry:
2021-03-08 18:12:59 +05:30
- Using Kubernetes 1.18+:
```shell
kubectl create secret docker-registry gitlab-registry --docker-server="$CI_REGISTRY" --docker-username="$CI_DEPLOY_USER" --docker-password="$CI_DEPLOY_PASSWORD" --docker-email="$GITLAB_USER_EMAIL" -o yaml --dry-run=client | kubectl apply -f -
```
- Using Kubernetes <1.18:
```shell
kubectl create secret docker-registry gitlab-registry --docker-server="$CI_REGISTRY" --docker-username="$CI_DEPLOY_USER" --docker-password="$CI_DEPLOY_PASSWORD" --docker-email="$GITLAB_USER_EMAIL" -o yaml --dry-run | kubectl apply -f -
```
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
The Kubernetes cluster integration exposes these
[deployment variables](../../../ci/variables/README.md#deployment-variables) in the
GitLab CI/CD build environment to deployment jobs. Deployment jobs have
2021-01-29 00:20:46 +05:30
[defined a target environment](../../../ci/environments/index.md#defining-environments).
2018-03-17 18:26:18 +05:30
2021-02-22 17:27:13 +05:30
| Variable | Description |
|----------------------------|-------------|
| `KUBE_URL` | Equal to the API URL. |
| `KUBE_TOKEN` | The Kubernetes token of the [environment service account](add_remove_clusters.md#access-controls). Prior to GitLab 11.5, `KUBE_TOKEN` was the Kubernetes token of the main service account of the cluster integration. |
| `KUBE_NAMESPACE` | The namespace associated with the project's deployment service account. In the format `<project_name>-<project_id>-<environment>`. For GitLab-managed clusters, a matching namespace is automatically created by GitLab in the cluster. If your cluster was created before GitLab 12.2, the default `KUBE_NAMESPACE` is set to `<project_name>-<project_id>`. |
| `KUBE_CA_PEM_FILE` | Path to a file containing PEM data. Only present if a custom CA bundle was specified. |
| `KUBE_CA_PEM` | (**deprecated**) Raw PEM data. Only if a custom CA bundle was specified. |
| `KUBECONFIG` | Path to a file containing `kubeconfig` for this deployment. CA bundle would be embedded if specified. This configuration also embeds the same token defined in `KUBE_TOKEN` so you likely need only this variable. This variable name is also automatically picked up by `kubectl` so you don't need to reference it explicitly if using `kubectl`. |
2019-07-07 11:18:12 +05:30
| `KUBE_INGRESS_BASE_DOMAIN` | From GitLab 11.8, this variable can be used to set a domain per cluster. See [cluster domains](#base-domain) for more information. |
2018-03-17 18:26:18 +05:30
2020-04-08 14:13:33 +05:30
### Custom namespace
2021-01-03 14:25:43 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/27630) in GitLab 12.6.
> - An option to use project-wide namespaces [was added](https://gitlab.com/gitlab-org/gitlab/-/issues/38054) in GitLab 13.5.
The Kubernetes integration provides a `KUBECONFIG` with an auto-generated namespace
to deployment jobs. It defaults to using project-environment specific namespaces
of the form `<prefix>-<environment>`, where `<prefix>` is of the form
`<project_name>-<project_id>`. To learn more, read [Deployment variables](#deployment-variables).
You can customize the deployment namespace in a few ways:
- You can choose between a **namespace per [environment](../../../ci/environments/index.md)**
or a **namespace per project**. A namespace per environment is the default and recommended
setting, as it prevents the mixing of resources between production and non-production environments.
- When using a project-level cluster, you can additionally customize the namespace prefix.
When using namespace-per-environment, the deployment namespace is `<prefix>-<environment>`,
but otherwise just `<prefix>`.
- For **non-managed** clusters, the auto-generated namespace is set in the `KUBECONFIG`,
but the user is responsible for ensuring its existence. You can fully customize
this value using
[`environment:kubernetes:namespace`](../../../ci/environments/index.md#configuring-kubernetes-deployments)
in `.gitlab-ci.yml`.
When you customize the namespace, existing environments remain linked to their current
namespaces until you [clear the cluster cache](#clearing-the-cluster-cache).
2021-02-22 17:27:13 +05:30
WARNING:
2021-03-11 19:13:27 +05:30
By default, anyone who can create a deployment job can access any CI variable in
2021-01-03 14:25:43 +05:30
an environment's deployment job. This includes `KUBECONFIG`, which gives access to
any secret available to the associated service account in your cluster.
To keep your production credentials safe, consider using
2021-03-11 19:13:27 +05:30
[protected environments](../../../ci/environments/protected_environments.md),
2021-01-03 14:25:43 +05:30
combined with either
- a GitLab-managed cluster and namespace per environment,
- *or*, an environment-scoped cluster per protected environment. The same cluster
can be added multiple times with multiple restricted service accounts.
2019-12-26 22:10:19 +05:30
2020-07-28 23:09:34 +05:30
### Integrations
2021-03-08 18:12:59 +05:30
#### Canary Deployments
2020-07-28 23:09:34 +05:30
Leverage [Kubernetes' Canary deployments](https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#canary-deployments)
and visualize your canary deployments right inside the Deploy Board, without
the need to leave GitLab.
[Read more about Canary Deployments](../canary_deployments.md)
2021-03-08 18:12:59 +05:30
#### Deploy Boards
2020-07-28 23:09:34 +05:30
2021-02-22 17:27:13 +05:30
GitLab Deploy Boards offer a consolidated view of the current health and
2021-03-11 19:13:27 +05:30
status of each CI [environment](../../../ci/environments/index.md) running on Kubernetes.
They display the status of the pods in the deployment. Developers and other
2020-07-28 23:09:34 +05:30
teammates can view the progress and status of a rollout, pod by pod, in the
workflow they already use without any need to access Kubernetes.
[Read more about Deploy Boards](../deploy_boards.md)
#### Viewing pod logs
2021-03-11 19:13:27 +05:30
GitLab enables you to view the logs of running pods in connected Kubernetes
2020-07-28 23:09:34 +05:30
clusters. By displaying the logs directly in GitLab, developers can avoid having
to manage console tools or jump to a different interface.
[Read more about Kubernetes logs](kubernetes_pod_logs.md)
#### Web terminals
> Introduced in GitLab 8.15.
When enabled, the Kubernetes integration adds [web terminal](../../../ci/environments/index.md#web-terminals)
support to your [environments](../../../ci/environments/index.md). This is based
on the `exec` functionality found in Docker and Kubernetes, so you get a new
2021-03-11 19:13:27 +05:30
shell session in your existing containers. To use this integration, you
2020-07-28 23:09:34 +05:30
should deploy to Kubernetes using the deployment variables above, ensuring any
deployments, replica sets, and pods are annotated with:
- `app.gitlab.com/env: $CI_ENVIRONMENT_SLUG`
- `app.gitlab.com/app: $CI_PROJECT_PATH_SLUG`
`$CI_ENVIRONMENT_SLUG` and `$CI_PROJECT_PATH_SLUG` are the values of
the CI variables.
You must be the project owner or have `maintainer` permissions to use terminals.
Support is limited to the first container in the first pod of your environment.
2019-10-12 21:52:04 +05:30
### Troubleshooting
2019-07-07 11:18:12 +05:30
2019-09-30 21:07:59 +05:30
Before the deployment jobs starts, GitLab creates the following specifically for
the deployment job:
- A namespace.
- A service account.
2019-02-15 15:39:39 +05:30
2021-02-22 17:27:13 +05:30
However, sometimes GitLab can not create them. In such instances, your job can fail with the message:
2019-07-07 11:18:12 +05:30
2020-05-24 23:13:21 +05:30
```plaintext
2019-07-07 11:18:12 +05:30
This job failed because the necessary resources were not successfully created.
```
2019-02-15 15:39:39 +05:30
2019-07-31 22:56:46 +05:30
To find the cause of this error when creating a namespace and service account, check the [logs](../../../administration/logs.md#kuberneteslog).
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
Reasons for failure include:
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
- The token you gave GitLab does not have [`cluster-admin`](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles)
2019-07-07 11:18:12 +05:30
privileges required by GitLab.
- Missing `KUBECONFIG` or `KUBE_TOKEN` variables. To be passed to your job, they must have a matching
2020-05-24 23:13:21 +05:30
[`environment:name`](../../../ci/environments/index.md#defining-environments). If your job has no
2021-02-22 17:27:13 +05:30
`environment:name` set, the Kubernetes credentials are not passed to it.
2019-02-15 15:39:39 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2019-09-30 21:07:59 +05:30
Project-level clusters upgraded from GitLab 12.0 or older may be configured
in a way that causes this error. Ensure you deselect the
[GitLab-managed cluster](#gitlab-managed-clusters) option if you want to manage
namespaces and service accounts yourself.
2020-07-28 23:09:34 +05:30
## Monitoring your Kubernetes cluster
Automatically detect and monitor Kubernetes metrics. Automatic monitoring of
[NGINX Ingress](../integrations/prometheus_library/nginx.md) is also supported.
[Read more about Kubernetes monitoring](../integrations/prometheus_library/kubernetes.md)
### Visualizing cluster health
2019-02-15 15:39:39 +05:30
2020-07-28 23:09:34 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/4701) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 10.6.
2021-03-11 19:13:27 +05:30
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/208224) to GitLab Free in 13.2.
2019-02-15 15:39:39 +05:30
2021-02-22 17:27:13 +05:30
When [Prometheus is deployed](#installing-applications), GitLab monitors the cluster's health. At the top of the cluster settings page, CPU and Memory utilization is displayed, along with the total amount available. Keeping an eye on cluster resources can be important, if the cluster runs out of memory pods may be shutdown or fail to start.
2019-02-15 15:39:39 +05:30
2019-07-31 22:56:46 +05:30
![Cluster Monitoring](img/k8s_cluster_monitoring.png)