To enable metrics expose from keycloak you need to install in kubernetes with helm and set value
helm install keycloak bitnami/keycloak \
--set metrics.enabled=true \
--set <your values>
after this deploy your keycloak expose metrics in kubernetes on http://keycloak.keycloak.svc.cluster.local/relams/master/metrics
For access with basic auth and encryption from outside the kubernetes you need to deploy kubernetes ingress object with basic autentification and tls encryption. For this do.
-
Create a Secret for Basic Authentication
First, generate a .htpasswd file containing the username and a hashed password. For example, to create a user named prometheus with a password, use the htpasswd utility:
htpasswd -c auth prometheus
This command will prompt for a password and create a file named auth in the current directory. Next, create a Kubernetes Secret from this file:
kubectl create secret generic basic-auth --from-file=auth
This creates a Secret named basic-auth in your current namespace, containing the auth file as a key in its data.
-
Create self signed certificate as its created in section Authentication
-
Create kubernetes secret from this certificate
kubectl create secret tls keycloak-local-tls \
--cert=exporter.crt \
--key=exporter.key
Create the yaml file of ingress with tls and basic auth
nano keycloak-metrics.yaml
and paste into opened file
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: keycloak-metrics
annotations:
keycloak.ingress.kubernetes.io/auth-type: basic #basic auth annotation
keycloak.ingress.kubernetes.io/auth-secret: basic-auth #basic auth annotation
keycloak.ingress.kubernetes.io/auth-realm: 'Authentication Required - user' #basic auth annotation
spec:
ingressClassName: nginx
tls:
- hosts:
- keycloak-metrics.com
secretName: keycloak-local-tls
rules:
- host: keycloak-metrics.com
http:
paths:
- path: /metrics
pathType: Prefix
backend:
service:
name: keycloak
port:
number: 80
Save and exit from file. And create ingress object. For this run
kubectl apply -f keycloak-metrics.yaml
After deploy ingress, metrics of your ingress controller will exposed on url: https://keycloak-metrics.com/metrics
after login to this URL you will see some like this:
Enjoy!)