To enable metrics expose from kubernetes with kube state metrics you need to deploy it in kubernetes with helm and set value
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-state-metrics prometheus-community/kube-state-metrics --namespace monitoring
after this deploy your kubernetes expose metrics in kubernetes on http://kube-state-metrics.monitoring.svc.cluster.local:8080/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 kube-state-local-tls \
--cert=exporter.crt \
--key=exporter.key
Create the yaml file of ingress with tls and basic auth
nano kube-state-metrics.yaml
and paste into opened file
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kube-state-metrics
annotations:
nginx.ingress.kubernetes.io/auth-type: basic #basic auth annotation
nginx.ingress.kubernetes.io/auth-secret: basic-auth #basic auth annotation
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - user' #basic auth annotation
spec:
ingressClassName: nginx
tls:
- hosts:
- kube-state-metrics.com
secretName: kube-state-local-tls
rules:
- host: kube-state-metrics.com
http:
paths:
- path: /metrics
pathType: Prefix
backend:
service:
name: kube-state-metrics
port:
number: 8080
Save and exit from file. And create ingress object. For this run
kubectl apply -f kube-state-metrics.yaml
After deploy ingress, metrics of your kubernetes will exposed on url: https://kube-state-metrics.com/metrics
after login to this URL you will see some like this:
Enjoy!)