2023-02-13 12:29:03 +00:00
---
weight: 3
2024-07-30 07:59:29 +00:00
title: Kubernetes Monitoring with VictoriaMetrics Cloud
2023-02-13 12:29:03 +00:00
menu:
docs:
2024-07-30 07:59:29 +00:00
parent: "cloud"
2023-02-13 12:29:03 +00:00
weight: 3
2023-05-01 10:19:31 +00:00
aliases:
2024-07-30 07:59:29 +00:00
- /victoriametrics-cloud/how-to-monitor-k8s/index.html
- /managed-victoriametrics/how-to-monitor-k8s/index.html
2023-02-13 12:29:03 +00:00
---
2023-02-02 08:56:41 +00:00
Monitoring kubernetes cluster is necessary to build SLO/SLI, to analyze performance and cost-efficiency of your workloads.
2023-05-10 07:50:41 +00:00
To enable kubernetes cluster monitoring, we will be collecting metrics about cluster performance and utilization from kubernetes components like `kube-api-server` , `kube-controller-manager` , `kube-scheduler` , `kube-state-metrics` , `etcd` , `core-dns` , `kubelet` and `kube-proxy` . We will also install some recording rules, alert rules and dashboards to provide visibility of cluster performance, as well as alerting for cluster metrics.
2023-02-02 08:56:41 +00:00
For node resource utilization we will be collecting metrics from `node-exporter` . We will also install dashboard and alerts for node related metrics
For workloads monitoring in kubernetes cluster we will have [VictoriaMetrics Operator ](https://docs.victoriametrics.com/operator/VictoriaMetrics-Operator.html ). It enables us to define scrape jobs using kubernetes CRDs [VMServiceScrape ](https://docs.victoriametrics.com/operator/design.html#vmservicescrape ), [VMPodScrape ](https://docs.victoriametrics.com/operator/design.html#vmpodscrape ). To add alerts or recording rules for workloads we can use [VMRule ](https://docs.victoriametrics.com/operator/design.html#vmrule ) CRD
2023-02-06 10:33:40 +00:00
## Overview
2023-02-02 08:56:41 +00:00
In this guide we will be using [victoria-metrics-k8s-stack ](https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-k8s-stack ) helm chart
2023-05-10 07:50:41 +00:00
This chart will install `VMOperator` , `VMAgent` , `NodeExporter` , `kube-state-metrics` , `grafana` and some service scrape configurations to start monitoring kubernetes cluster components
2023-02-02 08:56:41 +00:00
2023-02-06 10:33:40 +00:00
## Prerequisites
2024-01-15 17:16:26 +00:00
2024-07-30 07:59:29 +00:00
2024-08-06 13:54:52 +00:00
- Active VictoriaMetrics Cloud instance. You can learn how to sign up for VictoriaMetrics Cloud [here ](https://docs.victoriametrics.com/victoriametrics-cloud/quickstart#how-to-register ).
2023-02-02 08:56:41 +00:00
- Access to your kubernetes cluster
2023-02-06 10:33:40 +00:00
- Helm binary. You can find installation [here ](https://helm.sh/docs/intro/install/ )
2023-02-02 08:56:41 +00:00
2023-02-06 10:33:40 +00:00
## Installation steps
2023-02-02 08:56:41 +00:00
Install the Helm chart in a custom namespace
2023-02-06 10:33:40 +00:00
1. Create a unique Kubernetes namespace, for example `monitoring`
2024-01-15 17:16:26 +00:00
2024-01-27 18:08:07 +00:00
```shell
2023-02-06 10:33:40 +00:00
kubectl create namespace monitoring
```
2024-01-15 17:16:26 +00:00
2023-07-26 21:39:35 +00:00
1. Create kubernetes-secrets with token to access your dbaas deployment
2024-01-15 17:16:26 +00:00
2024-01-27 18:08:07 +00:00
```shell
2023-02-06 10:33:40 +00:00
kubectl --namespace monitoring create secret generic dbaas-write-access-token --from-literal=bearerToken=your-token
kubectl --namespace monitoring create secret generic dbaas-read-access-token --from-literal=bearerToken=your-token
```
2024-01-15 17:16:26 +00:00
2023-02-06 10:33:40 +00:00
You can find your access token on the "Access" tab of your deployment
2024-07-24 08:00:31 +00:00
![K8s Monitoring ](kubernetes_monitoring.webp )
2023-07-26 21:39:35 +00:00
1. Set up a Helm repository using the following commands:
2024-01-15 17:16:26 +00:00
2024-01-27 18:08:07 +00:00
```shell
2023-02-06 10:33:40 +00:00
helm repo add grafana https://grafana.github.io/helm-charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add vm https://victoriametrics.github.io/helm-charts
helm repo update
```
2024-01-15 17:16:26 +00:00
2023-07-26 21:39:35 +00:00
1. Create a YAML file of Helm values called dbaas.yaml with following content
2023-10-09 14:25:45 +00:00
2023-02-06 10:33:40 +00:00
```yaml
externalVM:
read:
url: < reading url , you can find it in examples on Access page >
bearerTokenSecret:
name: dbaas-write-access-token
key: bearerToken
write:
url: < reading url , you can find it in examples on Access page >
bearerTokenSecret:
name: dbaas-read-access-token
key: bearerToken
vmsingle:
enabled: false
vmcluster:
enabled: false
vmalert:
enabled: true
spec:
evaluationInterval: 15s
vmagent:
enabled: true
spec:
scrapeInterval: 30s
externalLabels:
cluster: < your cluster name >
# dependencies
# Grafana dependency chart configuration. For possible values refer to https://github.com/grafana/helm-charts/tree/main/charts/grafana#configuration
grafana:
enabled: true
```
2024-01-15 17:16:26 +00:00
2023-07-26 21:39:35 +00:00
1. Install VictoriaMetrics-k8s-stack helm chart
2024-01-15 17:16:26 +00:00
2024-01-27 18:08:07 +00:00
```shell
2023-02-06 10:33:40 +00:00
helm --namespace monitoring install vm vm/victoria-metrics-k8s-stack -f dbaas.yaml -n monitoring
```
2024-01-15 17:16:26 +00:00
2023-02-02 08:56:41 +00:00
2023-02-06 10:33:40 +00:00
## Connect grafana
2023-02-02 08:56:41 +00:00
2023-02-06 10:33:40 +00:00
Connect to grafana and create your datasource
2023-02-02 08:56:41 +00:00
> If you are using external grafana, you can skip steps 1-3 and you will need to import dashboards that can be found here manually
1. Get grafana password
2024-01-15 17:16:26 +00:00
2024-01-27 18:08:07 +00:00
```shell
2023-02-06 10:33:40 +00:00
kubectl --namespace monitoring get secret vm-grafana -o jsonpath="{.data.admin-password}" | base64 -d
```
2024-01-15 17:16:26 +00:00
2023-07-26 21:39:35 +00:00
1. Connect to grafana
2024-01-15 17:16:26 +00:00
2024-01-27 18:08:07 +00:00
```shell
2023-02-06 10:33:40 +00:00
kubectl --namespace monitoring port-forward service/vm-grafana 3000:80
```
2024-01-15 17:16:26 +00:00
2024-08-06 13:54:52 +00:00
1. Open grafana in your browser `http://localhost:3000/datasources`
2023-02-02 08:56:41 +00:00
Use admin as username and password from previous step
2023-07-26 21:39:35 +00:00
1. Click on add datasource
2023-02-02 08:56:41 +00:00
Choose VictoriaMetrics or Prometheus as datasource type. Make sure you made this datasource as default for dashboards to work.
2023-02-06 10:33:40 +00:00
> You can find token and URL in your deployment, on Access tab
2024-07-24 08:00:31 +00:00
![K8s datasource ](how-to-monitor-k8s_datasource.webp )
2023-02-02 08:56:41 +00:00
2023-02-06 10:33:40 +00:00
## Test it
2023-02-02 08:56:41 +00:00
2024-08-06 13:54:52 +00:00
- You should be able to see data that was sent to your dbaas using VMAgent dashboard `http://localhost:3000/d/G7Z9GzMGz/victoriametrics-vmagent/`
2023-05-10 07:50:41 +00:00
- You also will be able to see bunch of kubernetes dashboards in your grafana