Grafana is a cross-platform open source tool for metric analysis and visualization. It supports visually querying and displaying collected data. This topic describes how to install Grafana in a cluster and integrate Grafana with a workspace of Volcengine Managed Service for Prometheus (VMP).
Background
You can install Grafana in a Volcengine Kubernetes Engine (VKE) cluster by using an open source image or deployment script. The following table describes the main differences between the two deployment methods.
Prerequisites
- A VMP workspace has been created, and basic authentication has been enabled. For details, see Creating workspaces.
- A VKE cluster is created and bound to the VMP workspace. For more details, refer to VKE integration.
- When you use the script to install Grafana, you need to use wget, echo, curl, and sed in your local environment (Linux/Mac). Ensure that these command-line tools are installed on your system.
Procedure
tip
This topic briefly describes how to deploy Grafana in a VKE cluster, which does not involve the high availability configuration. If you require high availability, use an external database (such as MySQL or Postgres) to replace Grafana's embedded SQLite3 database. For more details, refer to the official documentation. Step 1: Install Grafana by using an open source image
- In the top navigation bar, select the region where your business is located.
- In the left navigation pane, click Cluster. In the cluster list, click the target cluster name to go to the cluster details page.
- Click Workload > Resource Explorer in the left navigation pane. Click Create with Yaml to create a StorageClass (SC).
- Select Custom from the Type drop-down menu.
- Enter the YAML configuration in the Yamlfield.
- Click Workload > Resource Explorer in the left navigation pane. Click Create with Yaml to create a PersistentVolumeClaim (PVC).
- Select Custom from the Type drop-down menu.
- Enter the Yml configuration in the Yaml field.
- Click Workload > Deployment in the left navigation pane. On the page that appears, click Create with Yaml to create a workload of Grafana.
- In the left navigation pane, click Services and Ingresses > Service. On the page that appears, click Create with Yaml to create a Grafana service.
Step 2: Integrate a workspace data source
- Run the following command to configure Grafana port forwarding:
- Open a browser in your local environment (Linux/Mac), paste localhost:3000 into the address bar, and then press Enter to go to the Grafana login page. Log in to Grafana by using the default username admin and password admin.
- Click Connections > Data sources in the left navigation pane.
-
- Click Add data source to create a new data source.
-
- On the Add data source page, click Prometheus.
-
- In the HTTP section, paste the query URL of the workspace in the Prometheus server URL field.
-
- Switch on Basic auth in the Auth section and configure the username and password used for workspace authentication in the Basic Auth Details section.
-
- Click Save & test at the bottom of the page. When the message Successfully queried the Prometheus API is displayed, it indicates the workspace is integrated with Grafana.
-
Step 3: Create a dashboard
- Click Dashboards in the left navigation pane.
-
- Click New to create or import an observability dashboard.
-
Step 4: View a dashboard
- Click Dashboards in the left navigation pane.
- Click the created dashboard to view monitoring information.
-
Other operations
Deploy Grafana by using the deployment script
Default specifications
The following table shows the default instance specifications when you use the script to deploy Grafana.
Deploy Grafana (default configuration)
warning
You cannot modify or add authentication methods for Grafana that is deployed through the script. Confirm whether to use AK/SK authentication or basic authentication before deployment. If you need to modify the authentication method after deployment, you must first delete the deployed Grafana and redeploy it with the new authentication method. For more details, refer to Delete Grafana by using the deployment script. You can use the deployment script to quickly deploy Grafana. You can perform the following steps to deploy the default configurations:
- Use kubectl to connect to the cluster.
- Run the following command to deploy Grafana.
tip
This topic takes AK/SK authentication as an example. If you need to use basic authentication, you need to modify the values of the --access-key and --secret-key parameters to --basic-auth-username and --basic-auth-password. For more details, refer to the Use the --help parameter of the deployment script section of this topic. Deploy Grafana (mount PVC)
You can mount a PVC in Grafana to achieve persistent storage. Procedure:
- Use kubectl to connect to the cluster.
- Run the following command to deploy Grafana and mount a PVC:
tip
This topic takes AK/SK authentication as an example. If you need to use basic authentication, you need to modify the values of the--access-key and --secret-key parameters to --basic-auth-username and --basic-auth-password. For more details, refer to the Use the --help parameter of the deployment script section of this topic. Use the deployment script to delete Grafana
When the configurations of Grafana are invalid or do not meet the requirements, you can use the script to delete the deployed Grafana.
- Use kubectl to connect to the cluster.
- Run the following command to delete the deployed Grafana:
Use the --help parameter of the deployment script
You can view all the predefined fields and their meanings in the installation script by using the --help parameter.
The following section describes the meanings and examples of different fields in the installation script.