Metrics

Overview

Goal

Configure the Microgateway to publish metrics. Prometheus scrapes those metrics and Grafana will visualize them.

Notes

Microgateway provides also metrics about authenticated sessions. Keep in mind that this is a premium feature and requires a valid license.

Without a valid license, Airlock Microgateway runs as Community Edition. For more details see Features and support.

Preparation

  1. Deploy the Kubernetes exercise
  2. Run the following commands:
  3. copy
    cd metrics/exercise/
    copy
    kubectl apply -k .
  4. The exercise has been deployed successfully.

The exercise does not contain any licenses. Therefore, Airlock Microgateway runs as Community Edition

For more details see Features and support.

To run the exercise as Premium Edition, copy a valid license to .templates/microgateway/secret/microgateway.lic and execute kubectl apply -k . to re-deploy the Microgateway.

Instruction

  1. Change the Microgateway configuration
  2. Connect to the website:
    • Open the URL in your browser: https://<MINIKUBE_IP>/
    • Check the following:
    • Are metrics shown for the pod echo-microgateway and grafana-microgateway?
    details...
    • The following should be noticed:
    • Metrics for the service echo-microgateway are shown but the metrics for the pod echo-microgateway-xxx are missing.
  3. Open Prometheus:
    • Open the URL in your browser: https://<MINIKUBE_IP>/prometheus/
  4. Go to: Status >> Targets
    • The following should be noticed:
    • An error is displayed for the endpoint http://<cluster ip of echo-microgateway pod>:9090/metrics
    • server returned HTTP status 404 Not Found
  5. Check the status of the echo-microgateway pod.
  6. details...

    List the Microgateway pod

    copy
    kubectl get pod

    Show details of the echo-microgateway pod

    copy
    kubectl describe pod echo-microgateway
    details...
    • The following should be noticed:
    • The Prometheus interface in Microgateway runs on port 9102. The pod echo-microgateway is configured to expose this port.
    • Prometheus tries to scrape the metrics from port 9090 which obviously does not work.
    • Prometheus is configured for service discovery. For that it uses the following annotations:
    • prometheus.io/scrape: "true" 
      prometheus.io/port: "9102"

      prometheus.io/scrape tells Prometheus, whether the metrics should be scraped or not.

      prometheus.io/port tells Prometheus on which port it must scrape the metrics.

    • The kubectl describe pod command shows the following:
    • ...
      Annotations:  prometheus.io/port: 9090 
                    prometheus.io/scrape: true
      ...
      ...  
      Containers: 
        microgateway: 
      ... 
          Ports:          8080/TCP, 8443/TCP, 9090/TCP, 9102/TCP
      ... 

      This means, that the annotation prometheus.io/port: 9090 is incorrect for the deployment echo-microgateway.

  7. Edit the echo-microgateway deployment definition.
    • Configure the following settings in the echo-microgateway deployment definition:
    • deployment.spec.template.metadata.annotations['prometheus.io/port']
    details...
    1. Modify the deployment:
    2. Retrieve the current deployment definition:
    3. copy
      kubectl get deployments echo-microgateway -o yaml > echo-microgateway-deployment.yaml
    4. Adapt the file echo-microgateway-deployment.yaml to your needs.
    5. Update the Microgateway deployment.
    6. copy
      kubectl apply -f echo-microgateway-deployment.yaml

    A new Microgateway pod will be deployed automatically after updating the Microgateway deployment.

    details...

    The modified part of the echo-microgateway-deployment.yaml file looks as follow:

    copy
    ...
       template: 
        metadata: 
          annotations: 
            prometheus.io/port: "9102" 
            prometheus.io/scrape: "true"  
          labels: 
            app: microgateway 
            backend: echo 
            purpose: microgateway-tutorial
    ...  
  8. Check the status of the echo-microgateway pod.
  9. details...

    List the Microgateway pods:

    copy
    kubectl get pod
    copy
    kubectl get pod -l app=microgateway,backend=echo

    Show Microgateway pod details:

    copy
     kubectl describe pod -l app=microgateway,backend=echo

    Once the pod is ready to process requests, the output of the kubectl describe command shows that the pod is ready.

    ...
       Conditions: 
      Type              Status 
      Initialized       True 
      Ready             True 
      ContainersReady   True 
      PodScheduled      True
    ...     
  10. Connect to the website:
    • Open the URL in your browser: https://<MINIKUBE_IP>/
    • Check the following:
    • Are metrics shown for the pod echo-microgateway and grafana-microgateway?
  11. Metrics are available for all desired services.

Cleanup

  1. Delete Kubernetes resources from previously exercises or solutions
  2. Run the following commands:
  3. copy
    kubectl delete all,ing,cm,secrets,pv,pvc,sa,roles,rolebindings,clusterroles,clusterrolebindings -l purpose=microgateway-tutorial
  4. All relevant Kubernetes resources in the namespace have been deleted successfully.