Yandex Managed Service for Kubernetes cluster monitoring with the help of Prometheus Operator with Yandex Monitoring support
Managed Service for Kubernetes enables you to export cluster object metrics to monitoring systems.
In this article, you will learn how to configure Yandex Managed Service for Kubernetes cluster monitoring with the help of Prometheus Operator with Yandex Monitoring support.
Prometheus Operator with Monitoring support streamlines the installation of Prometheus Operator, a popular solution for Kubernetes cluster monitoring, providing integration with Yandex Monitoring. You can use it to collect, store, and read metrics from containers, applications, and the infrastructure. The system leverages the Prometheus data model and PromQL
To set up monitoring for your Managed Service for Kubernetes cluster:
- Install Prometheus Operator using a Helm chart or Yandex Cloud Marketplace.
- Set up and test alerts.
- Visualize metrics.
If you no longer need the resources you created, delete them.
Required paid resources
The support cost for this solution includes:
- Fee for the Managed Service for Kubernetes master: (see Managed Service for Kubernetes pricing).
- Fee for Managed Service for Kubernetes cluster nodes: specifically using computing resources and storage (see Yandex Compute Cloud pricing).
- Fee for public IP addresses for Managed Service for Kubernetes cluster hosts and Managed Service for Kubernetes cluster nodes with public access enabled (see Yandex Virtual Private Cloud pricing).
Getting started
-
Create security groups for the Managed Service for Kubernetes cluster and its node groups.
Warning
The configuration of security groups determines the performance and availability of the cluster and the services and applications running in it.
-
Create a Managed Service for Kubernetes cluster and node group in any suitable configuration with internet access and the security groups you set up earlier.
-
Install kubect
and configure it to work with the new cluster. -
Create a service account with the monitoring.editor role.
-
Create an API key for the service account:
-
If you want to install Prometheus Operator using a Helm chart, run the following command and save the
secretkey you get:yc iam api-key create --service-account-name=<service_account_name> -
If you want to install Prometheus Operator using Cloud Marketplace, create an API key in JSON format and save it to the
sa-key.jsonfile:yc iam api-key create \ --service-account-name=<service_account_name> \ --format=json | jq -c > sa-key.jsonTip
You can also automatically create a new API key during the app installation.
-
-
Create a Prometheus workspace:
Management console- Open the Monitoring home page
. - In the left-hand panel, select Prometheus.
- Click Create workspace.
- Open the Monitoring home page
Install Prometheus Operator using a Helm chart
-
Install Helm
v3.8.0 or higher. -
Get the Prometheus workspace ID:
Management console- Open the Monitoring home page
. - Select Prometheus on the left.
- Select a Prometheus workspace.
- This will open the General information tab displaying the workspace ID. Save the ID.
- Open the Monitoring home page
-
To install a Helm chart
with Prometheus Operator, run this command:helm pull oci://cr.yandex/yc-marketplace/yandex-cloud/prometheus/kube-prometheus-stack \ --version 72.6.2-1 \ --untar && \ helm install \ --namespace <namespace_for_Prometheus_Operator> \ --create-namespace \ --set prometheusWorkspaceId=<Prometheus_workspace_ID> \ --set iam_api_key_value_generated.secretAccessKey=<secret_part_of_API_key> \ prometheus ./kube-prometheus-stack/This command will also create a new namespace for Prometheus Operator.
If you set
namespaceto the default namespace, Prometheus Operator may work incorrectly. Use a value different from all the existing namespaces, e.g.,prometheus-operator-space.Note
If you are using a Helm version below 3.8.0, append the
export HELM_EXPERIMENTAL_OCI=1 && \string to the command to enable Open Container Initiative (OCI) support in the Helm client. -
Make sure the Prometheus Operator pods have changed their status to
Running:kubectl get pods --namespace=<namespace_for_Prometheus_Operator> \ -l "release=prometheus"
Install Prometheus Operator using Cloud Marketplace
-
Navigate to the folder dashboard
and select Managed Service for Kubernetes. -
Click the name of the Kubernetes cluster you need and select the Marketplace tab.
-
Under Application available for installation, select Prometheus Operator with Monitoring support and click Go to install.
-
Configure the application:
- Namespace: Create a new namespace, e.g.,
prometheus-operator-space. If you leave the default namespace, Prometheus Operator may work incorrectly. - Application name: Specify the application name.
- Prometheus Workspace: Select a Prometheus workspace.
- API key: Specify the contents of the
sa-key.jsonfile.
- Namespace: Create a new namespace, e.g.,
-
Click Install.
-
Wait for the application to change its status to
Deployed.
Configure alerts based on metrics
-
Create a notification channel by selecting an available sending method.
-
Set up the Alert Manager
responsible for sending notifications:-
Open the Monitoring home page
. -
Select Prometheus on the left.
-
Select a Prometheus workspace.
-
Navigate to the Alert manager configuration tab.
-
Click Upload a configuration file and upload the configuration
file inYAMLformat.Sample configuration file
global: resolve_timeout: 5m route: receiver: telegram routes: - receiver: "null" matchers: - severity="none" continue: false receivers: - name: telegram yandex_monitoring_configs: - channel_names: - "<notification_channel_name>" - name: "null" yandex_monitoring_configs: - channel_names: []
-
-
Add a test alerting rule:
cat <<EOF | kubectl apply -f - apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: labels: release: kube-prometheus-stack name: test spec: groups: - name: test rules: - alert: Test annotations: description: this is a test alert summary: test alert expr: vector(1) labels: severity: warning EOF -
Wait until you get alerted through the selected notification channel or check the alert status in the management console:
- Open the Monitoring home page
. - Select Prometheus on the left.
- Select a Prometheus workspace.
- Navigate to the Managing rules tab.
- Click the test alert name.
- Navigate to the Alerts tab.
- Make sure the test alert status changed to
FIRING.
- Open the Monitoring home page
Visualize metrics
Build a chart based on the metrics and add it to the dashboard.
Build a chart based on metrics
Add the chart to the dashboard
- Build a chart.
- At the top right, click Add to dashboard.
- Enter a name for your chart.
- Select a cloud and folder.
- Select an existing dashboard or create a new one.
- Select a chart adding option:
- Add: To add the chart to the dashboard and stay in the Metrics section.
- Add and edit: To add the chart to the dashboard and go to the Dashboards section. The chart will not be saved in Metrics.
Tip
You can create an empty dashboard and then add the charts to it.
Delete the resources you created
Some resources are not free of charge. Delete the resources you no longer need to avoid paying for them:
- Delete the Managed Service for Kubernetes cluster.
- Delete the public static IP address for your Managed Service for Kubernetes cluster if you reserved one.