TheKoguryo's Tech Blog

Version 2023.06.19

Warning

This content has been generated by machine translation. The translations are automated and have not undergone human review or validation.

4.3.1 Installing Prometheus&Grafana

Install Prometheus

  1. Create a namespace for installation.

    kubectl create ns monitoring
    
  2. Register the repository for installation via Helm Chart. This example uses the Bitnami Helm Chart repository.

    helm repo add bitnami https://charts.bitnami.com/bitnami
    
  3. Setting value definition

    When installing Helm Chart, refer to the list of configurable parameters and input the value you want to change.

    cat <<EOF > values.yaml
    prometheus:
      ingress:
        enabled: true
        hostname: prometheus.ingress.thekoguryo.ml
        path: /
        annotations:
          kubernetes.io/ingress.class: nginx
          cert-manager.io/cluster-issuer: letsencrypt-staging
        tls: true
    alertmanager:
      ingress:
        enabled: true
        hostname: alertmanager.ingress.thekoguryo.ml
        path: /
        annotations:
          kubernetes.io/ingress.class: nginx
          cert-manager.io/cluster-issuer: letsencrypt-staging
        tls: true
    EOF
    
  4. Install prometheus helm chart

    helm install prometheus -n monitoring -f values.yaml bitnami/kube-prometheus
    
  5. Installation result

    Prometheus’ internal DNS information will be used later when linking with Grafana.

    oke_admin@cloudshell:~ (ap-seoul-1)$ helm install prometheus -n monitoring -f values.yaml bitnami/kube-prometheus
    NAME: prometheus
    
    ...
    
    Prometheus can be accessed via port "9090" on the following DNS name from within your cluster:
    
        prometheus-kube-prometheus-prometheus.monitoring.svc.cluster.local
    
    ...
    

Install Grafana

  1. Setting value definition

    When installing Helm Chart, refer to the list of configurable parameters and input the value you want to change.

    cat <<EOF > values.yaml
    admin:
      password: "higrafana"
    ingress:
      enabled: true
      hostname: grafana.ingress.thekoguryo.ml
      path: /
      annotations:
        kubernetes.io/ingress.class: nginx
        cert-manager.io/cluster-issuer: letsencrypt-staging
      tls: true
    EOF
    
  2. Install grafana helm chart

    helm install grafana -n monitoring -f values.yaml bitnami/grafana
    
  3. Installation result

    It is installed as follows, and it takes some time for the actual container to start.

    oke_admin@cloudshell:~ (ap-seoul-1)$ helm install grafana -n monitoring -f values.yaml bitnami/grafana
    NAME: grafana
    
    ...
    
    2. Get the admin credentials:
    
        echo "User: admin"
        echo "Password: $(kubectl get secret grafana-admin --namespace monitoring -o jsonpath="{.data.GF_SECURITY_ADMIN_PASSWORD}" | base64 --decode)"
    oke_admin@cloudshell:grafana (ap-seoul-1)$ echo "Password: $(kubectl get secret grafana-admin --namespace monitoring -o jsonpath="{.data.GF_SECURITY_ADMIN_PASSWORD}" | base64 --decode)"
    

Grafana settings

  1. Access the Grafana web UI.

    1. URL: ingress.hostname set in values.yaml

    2. Administrator account

      • User: admin

      • Password: admin.password set in values.yaml or if not entered, check with the following command

        echo "Password: $(kubectl get secret grafana-admin --namespace monitoring -o jsonpath="{.data.GF_SECURITY_ADMIN_PASSWORD}" | base64 --decode)"
        

    image-20211213113342794

  2. Select Configuration > Data sources from the left menu for Prometheus registration

    image-20211213115049819

  3. Click Add data source

  4. Select Prometheus

    image-20211213115211661

  5. Enter Prometheus connection information

    Enter the Prometheus internal connection information that you checked in the Prometheus installation log earlier.

    http://prometheus-kube-prometheus-prometheus.monitoring.svc.cluster.local:9090
    

    image-20211213115309836

  6. Click Save & test at the bottom

Add Grafana Dashboard

  1. You can use the published Grafana Dashboard for Kubernetes monitoring.

    image-20211213124309673

  2. Select the desired dashboard among the dashboards found on the above site.

  3. Confirm the ID on the dashboard detail page.

    image-20211213124722220

  4. Select Dashboards > Manage from the left menu for Dashboard registration

    image-20211213124910699

  5. Click Import

  6. Enter the dashboard ID to import (eg 7249) and click Load

  7. Select Prometheus registered data source and click Import

    image-20211213125202862

  8. Monitoring OKE cluster via imported dashboard

    image-20211213125437150

  9. You can monitor the Kubernetes cluster by using the dashboard published as above, or by creating a dashboard of your choice and using the metric information collected from Prometheus.



As an individual, this article was written with my personal time. There may be errors in the content of the article, and the opinions in the article are personal opinions.

Last updated on 13 Dec 2021