3 min read | by Jordi Prats
We can use the Kube Prometheus Stack Helm chart to deploy a full monitoring stack in Kubernetes. It's going to install Prometheus, AlertManager and Grafana with minumum configuration.
The first step is to add the Prometheus community Helm chart repository, which contains the necessary charts for setting it up:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
Next, we'll create a dedicated namespace for the Prometheus stack and install the Kube Prometheus Stack Helm chart into it:
kubectl create ns promstack
helm install promstack --namespace promstack prometheus-community/kube-prometheus-stack
Once the installation is complete, we can check the status of the pods to ensure everything is running:
$ kubectl get pods -n promstack
NAME READY STATUS RESTARTS AGE
promstack-grafana-574c64cbd9-dnd4m 0/3 ContainerCreating 0 18s
promstack-kube-prometheus-operator-79dc776f85-6cwnd 0/1 ContainerCreating 0 18s
promstack-kube-state-metrics-5cbfd64574-rw574 0/1 ContainerCreating 0 18s
promstack-prometheus-node-exporter-wbfn4 0/1 ContainerCreating 0 18s
We might get a ContainerCreating
status for a few minutes until all the containers are up and running. After a while, we should see the pods in a Running
state:
$ kubectl get pods -n promstack
NAME READY STATUS RESTARTS AGE
alertmanager-promstack-kube-prometheus-alertmanager-0 2/2 Running 0 39s
prometheus-promstack-kube-prometheus-prometheus-0 1/2 Running 0 39s
promstack-grafana-574c64cbd9-dnd4m 3/3 Running 0 119s
promstack-kube-prometheus-operator-79dc776f85-6cwnd 1/1 Running 0 119s
promstack-kube-state-metrics-5cbfd64574-rw574 1/1 Running 0 119s
promstack-prometheus-node-exporter-wbfn4 1/1 Running 0 119s
At this point, all components (Prometheus, Grafana, AlertManager, etc.) should be running.
The monitoring stack exposes several services, such as Prometheus, AlertManager, and Grafana, within your Kubernetes cluster. To check their details, run the following command:
$ kubectl get svc -n promstack
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 83s
prometheus-operated ClusterIP None <none> 9090/TCP 83s
promstack-grafana ClusterIP 10.96.2.187 <none> 80/TCP 2m43s
promstack-kube-prometheus-alertmanager ClusterIP 10.96.180.24 <none> 9093/TCP,8080/TCP 2m43s
promstack-kube-prometheus-operator ClusterIP 10.96.68.245 <none> 443/TCP 2m43s
promstack-kube-prometheus-prometheus ClusterIP 10.96.106.156 <none> 9090/TCP,8080/TCP 2m43s
promstack-kube-state-metrics ClusterIP 10.96.35.139 <none> 8080/TCP 2m43s
promstack-prometheus-node-exporter ClusterIP 10.96.92.218 <none> 9100/TCP 2m43s
Since we haven't configured any Ingress or LoadBalancer, we can access the services using port-forwarding.
To access Prometheus, we can run:
kubectl port-forward svc/prometheus-operated 9090:9090 -n promstack
And then open a browser and navigate to http://localhost:9090
to access the Prometheus UI.
To access AlertManager, we can run:
kubectl port-forward svc/alertmanager-operated 9093:9093 -n promstack
This is going to use the local port 9093
to forward the traffic to the AlertManager service. We can then open a browser and navigate to http://localhost:9093
to access the AlertManager UI.
In the case of Grafana, we can run:
kubectl port-forward svc/promstack-grafana 9080:80 -n promstack
Notice that we are using the local port 9080
to forward the traffic to the Grafana service. We can then open a browser and navigate to http://localhost:9080
to access the Grafana UI.
Posted on 09/09/2024