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

  • Deploy the Kubernetes exercise
  • 1.
    Run the following commands:
  • copy
    cd metrics/exercise/
    copy
    kubectl apply -k .
  • 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

  • Change the Microgateway configuration
  • 1.
    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.
  • 2.
    Open Prometheus:
    • Open the URL in your browser: https://<MINIKUBE_IP>/prometheus/
  • 3.
    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
  • 4.
    Check the status of the echo-microgateway pod.
  • 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.

  • 5.
    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...
    • Modify the deployment:
    • 1.
      Retrieve the current deployment definition:
    • copy
      kubectl get deployments echo-microgateway -o yaml > echo-microgateway-deployment.yaml
    • 2.
      Adapt the file echo-microgateway-deployment.yaml to your needs.
    • 3.
      Update the Microgateway deployment.
    • 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
    ...  
  • 6.
    Check the status of the echo-microgateway pod.
  • 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
    ...     
  • 7.
    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?
  • Metrics are available for all desired services.

Cleanup

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