Skip to content

Deploy an Application with Metrics Monitoring

Edward Mezarina edited this page Nov 15, 2021 · 5 revisions

This tutorial will show how you can customize your outerloop with a service monitor deployment for metrics monitoring by Prometheus using a sample Dockerfile and deployment manifest here.

  1. Log in to your cluster.

  2. Clone the devfile stack intro project .

    git clone https://github.com/OpenLiberty/devfile-stack-intro.git
    cd devfile-stack-intro
  3. Download the custom outerloop Dockerfile and app-deploy.yaml.

    curl -sL https://raw.githubusercontent.com/awisniew90/sample-ol-stack-monitoring/main/Dockerfile --output Dockerfile
    curl -sL https://raw.githubusercontent.com/awisniew90/sample-ol-stack-monitoring/main/app-deploy.yaml --output app-deploy.yaml
    • The custom Dockerfile adds a quick-start-security.xml file that uses env variables for username and password
    • The app-deploy.yaml sets these variables using a Secret named mysecret (created manually in the namespace) and creates a Service Monitor using the same username and password for authentication to the app's /metrics endpoint.
  4. Create the Secret in the target namespace with the following template:

    apiVersion: v1
    kind: Secret
    metadata:
      name: mysecret
      namespace: <target_namespace>
    type: Opaque
    stringData:
      username: <username>
      password: <password>
  5. The deployed Service Monitor will have the label monitoring=''. Make sure Prometheus is configured to select this Service Monitor in the target namespace. This can be done by editing the yaml of the Prometheus instance and adding:

    serviceMonitorSelector:
      matchExpressions:
        - key: monitoring
        operator: Exists

    Note: The Prometheus operator may need to be configured to watch multiple namespaces including the target namespace for your app deployment.

  6. Build the application image using the custom Dockerfile that is now in the current directory.

    docker build -t <docker-id>/devfile-stack-intro:1.0

    Note: This example tags the image so it can be pushed to a personal Docker repository. Replace <docker-id> with your Docker username.

  7. Push the image to an image repository

    docker push <docker-id>/devfile-stack-intro:1.0
  8. Open app-deploy.yaml and replace <CONTAINER_IMAGE> with the newly created image in Dockerhub.

    applicationImage: docker.io/<docker-id>/devfile-stack-intro:1.0
  9. Apply the changes using kubectl

    kubectl apply -f app-deploy.yaml

The Prometheus targets should now show the metrics endpoint of your deployment.