Setting up Kubernetes Addons
2023/06/11
See the GitHub repo for this post in kengz/k0s-cluster.
After creating a Kubernetes cluster, we would want to add a set of standard cluster addons using Helm for DevOps:
cert-manager: certificate management
cluster-autoscaler: to dynamically autoscale cluster by adding or reducing nodes.
metrics-server: for monitoring and and HPA (HorizontalPodAutoscaler) to work.
kubernetes-dashboard: basic cluster monitoring (if Lens is not available)
Loki (scalable): to aggregate and index all logs in the cluster, with retention policy; the logs are searchable in Grafana. Additionally:
promtail to aggregate logs
Note: Elasticsearch charts (hence ELK) have been deprecated in favor of their licensed ECK; plus Loki is much easier to run and maintain
kube-prometheus-stack: for cluster monitoring with many useful preconfigured cluster Prometheus metrics in Grafana dashboards. Additionally:
prometheus-adapter for custom metrics API, e.g. for HPA to scale using custom-defined metrics.
prometheus-pushgateway to push application metrics
prometheus-blackbox-exporter to probe endpoints for uptime monitoring
Additionally, install Lens for GUI monitoring and access to the cluster. Get a free license to use.
Installations
cert-manager
cluster-autoscaler
Helm chart here. This component has some custom settings dependending on which cloud provider is used, but the main gist is:
metrics-server
Helm chart here. Some kubernetes providers have this preinstalled, but the gist is:
kubernetes-dashboard
Manifest here - this installs more reliably than its Helm chart. First, prepare manifest to create a service account for dashboard access:
Then run:
Preferably, install Lens for GUI monitoring and access to the cluster (it connects using kubeconfig). Get a free license to use.
Loki
Helm chart here. Loki is a Grafana project for log aggregation - it is scalable (to TBs), cheap, and simple to maintain. The logs will show up in Grafana dashboards - which is a must-have for Kubernetes clusters.
Elasticsearch has archived their Helm charts and moved to a licensed model (ECK), I can no longer recommend it. Also, it is quite bloated and fragile just for log aggregation.
First, prepare the Helm override file to:
configure storage for scalable mode (s3/GCP/Azure etc., or use minio to try first)
We'll also install promtail as log aggregating agent.
Then run:
Grafana dashboard is installed later in kube-prometheus-stack; we will add Loki as a data source to it for log search on Grafana.
kube-prometheus-stack
Helm chart here. This includes kube-state-metrics, node-exporter, and Grafana: they gather kubernetes metrics from all the cluster nodes, and preconfigure many useful cluster metric dashboards.
Prepare the Helm override file to set/change default password, and add Loki as data source for log search in Grafana:
We will also install 3 additional Helm charts. The first is prometheus-adapter for custom metrics API, e.g. for HPA to scale using custom-defined metrics.
The second is Prometheus Pushgateway, e.g. to push application metrics. Specify Helm override file to configure ServiceMonitor with matching label so it is scraped by kube-prometheus-stack:
The third is Blackbox Exporter to probe endpoints for uptime monitoring. Specify the Helm override file to configure targets and ServiceMonitor with matching label so it is scraped by kube-prometheus-stack:
Now, install all of these by running:
Grafana Dashboards can also be provisioned via ConfigMaps. See the repo linked above for more examples as the ConfigMap file is large.
Accessing Dashboards
After installing the addons, access all the dashboards as follows:
just open the app, it will use
~/.kube/config
to connect
get token:
kubectl -n kubernetes-dashboard create token admin-user
run
kubectl proxy
and visit http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
Grafana for cluster and logging monitoring
data sources include kube-state-metrics, node-exporter, prometheus, and custom-added loki for logs
run
kubectl port-forward -n monitoring svc/prometheus-grafana 6060:80
and visit http://localhost:6060 to find the preconfigured dashboards(one-time) import this Loki Kubernetes Logs and this Blackbox exporter dashboards
Prometheus for cluster monitoring
run
kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090
and visit http://localhost:9090
See the GitHub repo for this post in kengz/k0s-cluster.
Last updated