Install Grafana in Workload Clusters Deployed by a Supervisor

This topic explains how to deploy Grafana to Tanzu Kubernetes Grid (TKG) workload clusters deployed to vSphere by a vSphere with Tanzu Supervisor.

Grafana lets you query, visualize, alert on, and explore metrics no matter where they are stored. Grafana provides tools to form graphs and visualizations from application data.

You can install Grafana on a workload cluster in two ways:

Install Grafana Using the Tanzu CLI

Prerequisites

Adhere to the following prerequisites.

Reference

Refer to the following topic as needed.

Install Grafana

Complete these steps to install the Grafana package.

  1. Create the namespace for Grafana.

    kubectl create ns tanzu-system-dashboards
    
  2. Get the latest Grafana package version for your repo.

    kubectl -n tkg-system get packages
    
    grafana.tanzu.vmware.com.7.5.16+vmware.1-tkg.1                       grafana.tanzu.vmware.com                       7.5.16+vmware.1-tkg.1   1h40m15s
    grafana.tanzu.vmware.com.7.5.16+vmware.1-tkg.2                       grafana.tanzu.vmware.com                       7.5.16+vmware.1-tkg.2   1h40m15s
    grafana.tanzu.vmware.com.7.5.17+vmware.1-tkg.1                       grafana.tanzu.vmware.com                       7.5.17+vmware.1-tkg.1   1h40m15s
    grafana.tanzu.vmware.com.7.5.17+vmware.2-tkg.1                       grafana.tanzu.vmware.com                       7.5.17+vmware.2-tkg.1   1h40m15s
    grafana.tanzu.vmware.com.7.5.7+vmware.1-tkg.1                        grafana.tanzu.vmware.com                       7.5.7+vmware.1-tkg.1    1h40m15s
    grafana.tanzu.vmware.com.7.5.7+vmware.2-tkg.1                        grafana.tanzu.vmware.com                       7.5.7+vmware.2-tkg.1    1h40m15s
    

    The latest Grafana version in the repository is 7.5.17+vmware.2-tkg.1. This is the vesion we install. Adjust the version as necessary to meet your requirements.

  3. Create the grafana-data-values.yaml file using either of the following options.

    1. Copy the example provided. See Grafana Components, Configuration, Data Values.
    2. Or, generate a grafana-default-values.yaml file.

      tanzu package available get grafana.tanzu.vmware.com/7.5.17+vmware.2-tkg.1 --default-values-file-output grafana-data-values.yaml
      
  4. Edit the grafana-data-values.yaml file and update the values.

    If you use a generated data values file, add the ingress.pvc: storageClassName and value, which is the name of the vSphere storage class accessible by the TKG cluster, as returned by kubectl get storageclass.

    To avoid a common error, remove the secret from the data values file and manually create the secret. See Secret not created when installing Grafana from default YAML file in Troubleshooting Workload Cluster Issues.

    Here is a minimal grafana-data-values.yaml with the storage class field added and the secret removed.

    grafana:
      deployment:
        replicas: 1
        updateStrategy: Recreate
      pvc:
        accessMode: ReadWriteOnce
        storage: 2Gi
      service:
        port: 80
        targetPort: 3000
        type: LoadBalancer
    ingress:
      enabled: true
      prefix: /
      servicePort: 80
      virtual_host_fqdn: grafana.system.tanzu
      pvc:
        storageClassName: vSphere-storage-profile
    namespace: grafana
    
    
  5. Install the Grafana package using the Tanzu CLI.

    tanzu package install grafana -p grafana.tanzu.vmware.com -v 7.5.17+vmware.2-tkg.1 --values-file grafana-data-values.yaml -n tanzu-system-dashboards
    
  6. Verify Grafana installation using the Tanzu CLI.

    tanzu package installed list -n tanzu-system-dashboards
    
    NAME     PACKAGE-NAME              PACKAGE-VERSION        STATUS
    grafana  grafana.tanzu.vmware.com  7.5.17+vmware.2-tkg.1  Reconcile succeeded
    
    tanzu package installed get grafana -n tanzu-system-dashboards
    
    NAME:                    grafana
    PACKAGE-NAME:            grafana.tanzu.vmware.com
    PACKAGE-VERSION:         7.5.17+vmware.2-tkg.1
    STATUS:                  Reconcile succeeded
    
  7. Verify Grafana installation using Kubectl.

    kubectl -n tanzu-system-dashboards get all
    
    kubectl -n tanzu-system-dashboards get pvc
    
    NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE                                 CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    grafana-pvc   Bound    pvc-243405bc-93e3-4570-bfdc-8451cbe503af   2Gi        RWO            vwt-policy     2m41s
    

Troubleshoot Grafana Installation

To avoid the error “Secret not created when installing Grafana from default YAML file,” remove the grafana.secret.* from the data values file and manually create the secret as described at the link.

Install Grafana Using Kubectl

Grafana provides you with tools to graph and visualize data. Install the Grafana package to generate and view metrics for TKG clusters.

Requirements

Adhere to the following requirements before you install the Contour package.

Note: To access the Grafana Dashboard from outside the cluster, deploy Contour with an Envoy service of type LoadBalancer or type NodePort. In addition, install Prometheus.

Reference

Refer to the following topic as needed.

Install Grafana

Install the Grafana package.

  1. List the available Grafana versions in the repository.

    kubectl get packages -n tkg-system
    

    The most recent Grafana version is grafana.tanzu.vmware.com.7.5.17+vmware.2-tkg.1.

  2. Create the Grafana namespace.

    kubectl create ns grafana-dashboard
    
  3. Create grafana-data-values.yaml.

    Start by copying the contents from grafana-data-values.yaml. Update values accordingly. See Grafana Components, Configuration, Data Values.

  4. Create the secret named grafana-data-values using the grafana-data-values.yaml file as input.

    kubectl create secret generic grafana-data-values --from-file=values.yaml=grafana-data-values.yaml -n tkg-system
    
    secret/grafana-data-values created
    
  5. Verify the secret.

    kubectl get secrets -A
    
    kubectl describe secret grafana-data-values -n tkg-system
    
  6. Customize grafana-data-values as needed for your environment.

    Refer to Grafana Components, Configuration, Data Values.

    If you update the data values, update the secret with the following command.

    kubectl create secret generic grafana-data-values --from-file=values.yaml=grafana-data-values.yaml -n tkg-system -o yaml --dry-run=client | kubectl replace -f-
    
    secret/grafana-data-values replaced
    
  7. Create the grafana.yaml specification.

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: grafana-sa
      namespace: tkg-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: grafana-role-binding
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
    subjects:
      - kind: ServiceAccount
        name: grafana-sa
        namespace: tkg-system
    ---
    apiVersion: packaging.carvel.dev/v1alpha1
    kind: PackageInstall
    metadata:
      name: grafana
      namespace: tkg-system
    spec:
      serviceAccountName: grafana-sa
      packageRef:
        refName: grafana.tanzu.vmware.com
        versionSelection:
          constraints: 7.5.17+vmware.2-tkg.1
      values:
      - secretRef:
          name: grafana-data-values
    
    
  8. Install the Grafana package.

    kubectl apply -f grafana.yaml
    
    serviceaccount/grafana-sa created
    clusterrolebinding.rbac.authorization.k8s.io/grafana-role-binding created
    packageinstall.packaging.carvel.dev/grafana created
    
  9. Verify Grafana installation.

    kubectl get all -n grafana-dashboard
    

Access the Grafana Dashboard Using a Contour Envoy Service of Type LoadBalancer

If the prerequisite Contour Envoy service of type LoadBalancer is deployed, and you specified this in the Grafana configuration file, obtain the external IP address of the load balancer and create DNS records for the Grafana FQDN.

  1. Get the External-IP address for the Envoy service of type LoadBalancer.

    kubectl get service envoy -n tanzu-system-ingress
    

    You should see the External-IP address returned, for example:

    
    NAME    TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)                      AGE
    envoy   LoadBalancer   10.99.25.220   10.195.141.17   80:30437/TCP,443:30589/TCP   3h27m
    

    Alternatively you can get the External-IP address using the following command.

    kubectl get svc envoy -n tanzu-system-ingress -o jsonpath='{.status.loadBalancer.ingress[0]}'
    
  2. To verify the installation of the Grafana extension, update your local /etc/hosts file with the Grafana FQDN mapped to the External-IP address of the load balancer, for example:

    127.0.0.1 localhost
    127.0.1.1 ubuntu
    #TKG Grafana Extension with Envoy Load Balancer
    10.195.141.17 grafana.system.tanzu
    
    
  3. Access the Grafana Dashboard by navigating to https://grafana.system.tanzu.

    Because the site uses self-signed certificates, you might need to navigate through a browser-specific security warning before you are able to access the dashboard.

  4. For production access, create two CNAME records on a DNS server that map the Envoy service Load Balancer External-IP address to the Grafana Dashboard.

Access the Grafana Dashboard Using a Contour Envoy Service of Type NodePort

If the prerequisite Contour Envoy service of type NodePort is deployed, and you specified this in the Grafana configuration file, obtain the virtual machine IP address of a worker node and create DNS records for the Grafana FQDN.

  1. Switch context to the vSphere Namespace where the cluster is provisioned.

    kubectl config use-context VSPHERE-NAMESPACE
    
  2. List the nodes in the cluster.

    kubectl get virtualmachines
    
  3. Pick one of the worker nodes and describe it using the following command.

    kubectl describe virtualmachines tkgs-cluster-X-workers-9twdr-59bc54dc97-kt4cm
    
  4. Locate the IP address of the virtual machine, for example Vm Ip: 10.115.22.43.

  5. To verify the installation of the Grafana extension, update your local /etc/hosts file with the Grafana FQDN mapped to a worker node IP address, for example:

    127.0.0.1 localhost
    127.0.1.1 ubuntu
    # TKG Grafana with Envoy NodePort
    10.115.22.43 grafana.system.tanzu
    
    
  6. Access the Grafana Dashboard by navigating to https://grafana.system.tanzu.

    Because the site uses self-signed certificates, you might need to navigate through a browser-specific security warning before you are able to access the dashboard.

check-circle-line exclamation-circle-line close-line
Scroll to top icon