-
Notifications
You must be signed in to change notification settings - Fork 8
Deploy an Application with Metrics Monitoring
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.
-
Log in to your cluster.
-
Clone the devfile stack intro project .
git clone https://github.com/OpenLiberty/devfile-stack-intro.git cd devfile-stack-intro
-
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.
-
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>
-
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.
-
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. -
Push the image to an image repository
docker push <docker-id>/devfile-stack-intro:1.0
-
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
-
Apply the changes using
kubectl
kubectl apply -f app-deploy.yaml
The Prometheus targets should now show the metrics endpoint of your deployment.