Hello K8s: Observability

Rodrigo Baron,β€’tutorialk8sprometheusgrafana

The last post about tutorial series of K8s dev/lab previous we install and then setup the resource management πŸ’ͺ, this is the last post from the tutorial series which we'll setup Metrics Server, Kube State Metrics, Prometheus and Grafana. The key component to ensure performance and reliability is an real-time monitoring with alerting capability, observability is one of core DevOps practices allowing granular insights to help develop good metrics and keep the system healthy. In this section we will incorporate Metrics server, Kube State Metrics, Prometheus and Grafana as the observability stack.

Metrics server

Metrics Server (opens in a new tab) collects resources metrics from Kubelets and exposes through K8s metrics api for use of Horizontal Pod Autoscaler (opens in a new tab) and Vertical Pod Autoscaler (opens in a new tab) making easier to debug autoscaling pipelines.

kubectl create -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/metrics-server/components.yaml

To check the deployment status:

kubectl get deployment metrics-server -n kube-system

Kube State Metrics

Kube State Metrics (opens in a new tab) generate raw metrics about the state of the objects such deployments, nodes and pods. It aim's to display unmodified comprehensible menssages and let the users apply any time heuristics as they need. This is designed to be consumed by Prometheus however any scraper could collect the metrics from the endpoint.

kubectl create -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/kube-state-metrics/cluster-role-binding.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/kube-state-metrics/cluster-role.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/kube-state-metrics/deployment.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/kube-state-metrics/service-account.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/kube-state-metrics/service.yaml

Prometheus

Prometheus is an monitoring and alerting tool with docker and K8s support, it can scrape metrics from nodes, containers, pods, services and user applications running in K8s cluster.

kubectl create -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/prometheus/00-namespace.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/prometheus/deployment.yml

It expose the metrics about the prometheus it's self to a node port 30000.

Grafana

Is a data visualization and analytics tool which supports alerting and notification with most major time-series databases such as Prometheus and Elasticsearch. It allow us create powerful dashboards making observability easier for our cluster and applications.

kubectl create -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/grafana/configmap.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/grafana/deployment.yaml \
               -f https://raw.githubusercontent.com/rodrigobaron/manifests/main/grafana/service.yaml

At sidebar click on + β†’ import then search for for dashboard ID 10000

Grafana

I told that is an old machine πŸ˜…. Also we could setup the Ingress and have a subdomain address but for simplicity let’s keep in this way.

Conclusion

So we reach the end of the K8s setup, this is the basic setup having the resources available for more sophisticated deployments services. There will more K8s posts and this will serve as reference for have the cluster setup in an old machine. See you soon πŸ‘‹

References

Β© Rodrigo Baron. Built with Vercel and Nextra.