Cluster monitoring
You can use the following tools to monitor the status of a Kubernetes cluster:
-
Preinstalled dashboard in the management console. VK Cloud creates it for each cluster automatically. It shows the status of cluster resources.
-
Kube Prometheus Stack monitoring add-on.
With the add-on, you can view metrics of Kubernetes resources, down to individual pods. You can also use alerts that warn you when a metric exceeds its threshold, and forecast cluster resource consumption. Forecasting is available in the add-on version
68.3.3.
VK Cloud creates a dashboard for each cluster automatically. The dashboard is based on Cloud Monitoring. It shows the status of cluster resources, how their usage changes, and the main resource consumers. The data comes from the metrics of nodes, containers, and the network. VK Cloud collects these metrics automatically.
The dashboard is available in the management console on the cluster page. Use its indicators to configure alerts in Cloud Monitoring.
The dashboard indicators fall into three groups:
-
Cluster health — key indicators that show whether the cluster has enough resources:
- CPU and memory usage of the cluster — actual resource consumption by all workloads. Values close to the maximum mean that the nodes have almost no spare computing resources.
- CPU and memory request usage — the share of allocatable resources on the node that pod requests reserve. If the value is high, the scheduler cannot place new pods, even if actual consumption is low. To fix this, try the solutions from Pods are stuck in the Pending state.
-
Cluster resources — how resource usage changes:
- CPU and memory dynamics — actual consumption compared with resource requests and limits. The dashboard also compares it with the share of allocatable resources on the node.
- Node utilization — CPU, memory, and filesystem usage for each node. Use it to find overloaded nodes and uneven load.
- Node network traffic — incoming and outgoing traffic for each node. Use it to notice sudden spikes in network load.
-
Resource consumers and risks — containers that use the most resources or are close to running out:
- Containers with the highest resource consumption. For such containers, check that resource requests and limits match the actual load. If you do not set them, the cluster uses default values.
- Containers close to the memory limit. If a container exceeds the limit, the Linux kernel stops its process because of lack of memory, and the container may restart. The list does not include containers without a limit.
-
Make sure that the monitoring add-on (
kube-prometheus-stack) is installed in a cluster. -
Make sure that you can connect to the cluster using
kubectl. -
Access the Grafana web interface:
-
Find the Grafana service name using the following command:
kubectl -n prometheus-monitoring get svc -l app.kubernetes.io/name=grafanaThe command output will show the Grafana service name in the format
<APP_NAME>-grafana. If the app name was auto-generated when installed via the management console, the service name will look likeaddon-<HASH>-grafana, for example,addon-c01ea19419-grafana. -
Grant external access to Grafana via
port-forwardusing the service name:kubectl -n prometheus-monitoring port-forward service/<GRAFANA_SERVICE_NAME> 8001:80 -
From the output of the command identify the port opened by
kubectlto access Grafana.The port number is specified before the → symbol. For example, in this output the port
6637is used to connect:Forwarding from 127.0.0.1:6637 -> 3000Forwarding from [::1]:6637 -> 3000 -
Open in your browser the URL for accessing the Grafana web interface:
http://localhost:<PORT>/The Grafana authorization page will appear.
-
-
Sign in to Grafana. Depending on the parameters with which the add-on was installed, use:
- Login
adminand temporary password. The password will need to be changed after the first authorization. - Login
adminand a permanent password from the Kubernetes secret.
- Login
Now you can work with Grafana. For example, it is possible to create and view dashboards. Preconfigured dashboards with information about various Kubernetes resources are available in the Dashboards → Browse side menu.
Read more about working with Grafana in official documentation.
The kube-prometheus-stack monitoring add-on version 68.3.3 includes built-in alerts that notify you if it forecasts that specific cluster resources will run out within a given time. The add-on also provides Grafana dashboards that show current resource consumption forecasts.
The add-on builds forecasts using the linear regression method: the add-on builds a linear function from the metric values it collects at a given interval within a given period, and calculates the forecast as the value of this function at a given time in the future. It expresses the result as a percentage of the maximum resource capacity on the Kubernetes object.
-
Make sure that you have installed version
68.3.3of thekube-prometheus-stackmonitoring add-on in the cluster. -
Go to the
kube-prometheus-stackadd-on code editing page and make sure that thegrafana.alerts.enabledparameter in the code is set totrue. This value is assigned to the parameter when the add-on is installed. -
If this parameter was changed to
false, set it back totrueand save the updated settings. -
Sign in to Grafana.
-
In the side menu, go to the Dashboards section.
-
In the list of dashboards in the VK Cloud section, open the K8s Resources Prediction dashboard.
-
View the available resource consumption forecasts:
- CPU Leaders: forecast of CPU consumption by worker nodes
- Memory Leaders: forecast of RAM consumption by worker nodes
- Persistent Volume Leaders: forecast of space consumption on a persistent volume (PV)
- Inode Leaders: forecast of index descriptor (inode) consumption on a persistent volume
-
(Optional) Adjust how forecasts are displayed using Grafana controls.
-
(Optional) Change the parameters used to calculate forecasts:
- Analysis period: the time interval up to the current moment whose data the add-on uses to build the forecast function
- Forecast horizon: the interval between the current moment and the future moment for which the add-on calculates the forecast
-
In the side menu, go to Alerting → Alert rules.
-
In the Grafana block, expand the VK Cloud > K8s Resources Prediction folder and view the built-in resource exhaustion alerts:
- K8sNodeCpuPrediction: a worker node has no free CPU.
- K8sNodeMemoryPrediction: a worker node has no free RAM.
- K8sPersistentVolumeCapacityPrediction: a persistent volume has no free space.
- K8sPersistentVolumeInodePrediction: a persistent volume has no free index descriptors.
These alerts have the following parameters:
- Analysis period:
1 week - Sampling interval:
10 minutes - Forecast horizon:
1 day - Alert threshold:
100%
You cannot change the parameters of built-in alerts, but you can create your own alert based on a built-in one.
-
(Optional) Create your own alert based on a built-in one:
-
In the list of alerts, click the copy button for the built-in alert you need, for example,
K8sNodeCpuPrediction. -
Read the warning and click Copy.
The Add rule page will open. In the 2 Define query and alert condition section, the query string will appear under the A label. For the
K8sNodeCpuPredictionalert, it looks like this:predict_linear(avg(instance:node_cpu_utilisation:rate5m * 100 * on(instance) group_left(nodename) node_uname_info{nodename!~".*master.*"}) by (nodename) [1w:10m],86400)This query contains the following values:
100— alert threshold in percent1w— analysis period10m— sampling interval86400— forecast horizon in seconds
-
Change the values as needed. The forecast horizon is set only in seconds, while for the analysis period and sampling interval, other units are available.
-
Configure other alert parameters as described in the official Grafana documentation.
-
Save the changes.
-
-
Configure how Grafana delivers notifications when built-in and custom alerts fire.
Forecasting setup is complete.
Now you can:
- receive notifications about resource exhaustion
- when you receive a notification, view forecasts for other objects to resolve potential problems in advance
- view current forecasts and compare them with the consumption dynamics shown on the standard Grafana dashboards
- refine forecasting parameters based on the comparison and create your own alerts