debian-mirror-gitlab/doc/user/project/integrations/prometheus_library/kubernetes.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
4.4 KiB
Markdown
Raw Normal View History

2020-05-24 23:13:21 +05:30
---
stage: Monitor
2022-04-04 11:22:00 +05:30
group: Respond
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-05-24 23:13:21 +05:30
---
2022-03-02 08:16:31 +05:30
# Monitoring Kubernetes (DEPRECATED) **(FREE)**
2018-03-17 18:26:18 +05:30
2022-03-02 08:16:31 +05:30
> [Deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/346541) in GitLab 14.7.
WARNING:
This feature is in its end-of-life process. It is [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/346541)
2022-06-21 17:19:12 +05:30
in GitLab 14.7, and is planned for removal in GitLab 16.0.
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
GitLab has support for automatically detecting and monitoring Kubernetes metrics.
## Requirements
2021-11-18 22:05:49 +05:30
The [Prometheus](../prometheus.md) and [Kubernetes](../../../infrastructure/clusters/index.md)
2018-03-17 18:26:18 +05:30
integration services must be enabled.
2017-09-10 17:25:29 +05:30
## Metrics supported
2018-05-09 12:01:36 +05:30
- Average Memory Usage (MB):
2020-04-08 14:13:33 +05:30
```prometheus
2019-09-30 21:07:59 +05:30
avg(sum(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}) by (job)) without (job) / count(avg(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}) without (job)) /1024/1024
```
2018-05-09 12:01:36 +05:30
- Average CPU Utilization (%):
2020-04-08 14:13:33 +05:30
```prometheus
2019-09-30 21:07:59 +05:30
avg(sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}[15m])) by (job)) without (job) / count(sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}[15m])) by (pod_name))
```
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
## Configuring Prometheus to monitor for Kubernetes metrics
2017-09-10 17:25:29 +05:30
2022-11-25 23:54:43 +05:30
Prometheus needs to be deployed into the cluster and configured properly to gather Kubernetes metrics. GitLab supports two methods for doing so:
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
- GitLab [integrates with Kubernetes](../../clusters/index.md), and can [query a Prometheus in a connected cluster](../../../clusters/integrations.md#prometheus-cluster-integration). The in-cluster Prometheus can be configured to automatically collect application metrics from your cluster.
2018-03-27 19:54:05 +05:30
- To configure your own Prometheus server, you can follow the [Prometheus documentation](https://prometheus.io/docs/introduction/overview/).
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
## Specifying the Environment
2023-04-23 21:23:45 +05:30
To isolate and only display relevant CPU and Memory metrics for a given environment, GitLab needs a method to detect which containers it is running. Because these metrics are tracked at the container level, traditional Kubernetes labels are not available.
2017-09-10 17:25:29 +05:30
2021-09-30 23:02:18 +05:30
Instead, the [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) or [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) name should begin with [CI_ENVIRONMENT_SLUG](../../../../ci/variables/index.md#predefined-cicd-variables). It can be followed by a `-` and additional content if desired. For example, a deployment name of `review-homepage-5620p5` would match the `review/homepage` environment.
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
## Displaying Canary metrics **(PREMIUM)**
2019-07-31 22:56:46 +05:30
2019-09-04 21:01:54 +05:30
GitLab also gathers Kubernetes metrics for [canary deployments](../../canary_deployments.md), allowing easy comparison between the current deployed version and the canary.
2019-07-31 22:56:46 +05:30
These metrics expect the [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) or [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) name to begin with `$CI_ENVIRONMENT_SLUG-canary`, to isolate the canary metrics.
### Canary metrics supported
- Average Memory Usage (MB)
2020-04-08 14:13:33 +05:30
```prometheus
2019-09-30 21:07:59 +05:30
avg(sum(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-canary-(.*)",namespace="%{kube_namespace}"}) by (job)) without (job) / count(avg(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-canary-(.*)",namespace="%{kube_namespace}"}) without (job)) /1024/1024
```
2019-07-31 22:56:46 +05:30
- Average CPU Utilization (%)
2020-04-08 14:13:33 +05:30
```prometheus
2019-09-30 21:07:59 +05:30
avg(sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod_name=~"^%{ci_environment_slug}-canary-(.*)",namespace="%{kube_namespace}"}[15m])) by (job)) without (job) / count(sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod_name=~"^%{ci_environment_slug}-canary-(.*)",namespace="%{kube_namespace}"}[15m])) by (pod_name))
```