|
| 1 | +# Kubernetes 1.33 Monitoring Guide |
| 2 | + |
| 3 | +Create a cluster with [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) |
| 4 | + |
| 5 | +``` |
| 6 | +cd monitoring\prometheus\kubernetes\1.33 |
| 7 | +
|
| 8 | +kind create cluster --name monitoring --image kindest/node:v1.33.1 --config kind.yaml |
| 9 | +``` |
| 10 | + |
| 11 | +Test our cluster to see all nodes are healthy and ready: |
| 12 | + |
| 13 | +``` |
| 14 | +kubectl get nodes |
| 15 | +NAME STATUS ROLES AGE VERSION |
| 16 | +monitoring-control-plane Ready control-plane 110s v1.33.1 |
| 17 | +monitoring-worker Ready <none> 98s v1.33.1 |
| 18 | +monitoring-worker2 Ready <none> 98s v1.33.1 |
| 19 | +monitoring-worker3 Ready <none> 98s v1.33.1 |
| 20 | +``` |
| 21 | + |
| 22 | +# Kube Prometheus |
| 23 | + |
| 24 | +The best method for monitoring, is to use the community project called `kube-prometheus` |
| 25 | +which you can find [here](https://github.com/prometheus-operator/kube-prometheus) |
| 26 | + |
| 27 | +This project focusses on compiling manifests for a complete kubernetes monitoring solution, so with it comes the Prometheus Operator, Grafana, Prometheus instances with Service Monitors that scrape all the internal Kubernetes metrics so we can monitor pods, workloads, nodes and applications. |
| 28 | + |
| 29 | +# Prometheus Community Helm Charts |
| 30 | + |
| 31 | +To deploy this, the best method is to use the Prometheus community helm charts which you can find [here](https://github.com/prometheus-community/helm-charts) |
| 32 | + |
| 33 | +``` |
| 34 | +helm repo add prometheus-community https://prometheus-community.github.io/helm-charts |
| 35 | +helm search repo prometheus-community --versions |
| 36 | +``` |
| 37 | + |
| 38 | +Check the possible configuration options: |
| 39 | + |
| 40 | +``` |
| 41 | +helm show values prometheus-community/kube-prometheus-stack > prometheus-values.yaml |
| 42 | +``` |
| 43 | + |
| 44 | +## Configation |
| 45 | + |
| 46 | +We can take anything from the values file and create our own `values.yaml` file to configure anything we want: |
| 47 | + |
| 48 | +``` |
| 49 | +``` |
| 50 | + |
| 51 | +## Installation |
| 52 | + |
| 53 | +Firstly let's list the available chart versions |
| 54 | + |
| 55 | +``` |
| 56 | +helm search repo prometheus-community --versions > versions.log |
| 57 | +``` |
| 58 | + |
| 59 | +Let's proceed with installation: |
| 60 | +``` |
| 61 | +CHART_VERSION=75.4.0 |
| 62 | +helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \ |
| 63 | + --version ${CHART_VERSION} \ |
| 64 | + --namespace monitoring \ |
| 65 | + --create-namespace \ |
| 66 | + --values values.yaml |
| 67 | +``` |
| 68 | + |
| 69 | +## Prometheus Operator |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +# Check Monitoring |
| 74 | + |
| 75 | +``` |
| 76 | +kubectl -n monitoring get pods |
| 77 | +NAME READY STATUS RESTARTS AGE |
| 78 | +grafana-7d484fc668-x4bf9 2/3 Running 0 58s |
| 79 | +kube-state-metrics-7dd4c79774-cdk7k 1/1 Running 0 58s |
| 80 | +node-exporter-brkpr 1/1 Running 0 58s |
| 81 | +node-exporter-k9tpq 1/1 Running 0 58s |
| 82 | +node-exporter-m9bfj 1/1 Running 0 58s |
| 83 | +node-exporter-w7ct4 1/1 Running 0 58s |
| 84 | +prometheus-kube-prometheus-stack-prometheus-0 1/2 Running 0 45s |
| 85 | +prometheus-operator-c95dfdfb6-jrjwr 1/1 Running 0 58s |
| 86 | +``` |
| 87 | + |
| 88 | +To see how Prometheus is configured on what to scrape , we list service monitors |
| 89 | + |
| 90 | +``` |
| 91 | +kubectl -n monitoring get servicemonitors |
| 92 | +NAME AGE |
| 93 | +grafana 92s |
| 94 | +kube-prometheus-stack-apiserver 92s |
| 95 | +kube-prometheus-stack-coredns 92s |
| 96 | +kube-prometheus-stack-kube-controller-manager 92s |
| 97 | +kube-prometheus-stack-kube-etcd 92s |
| 98 | +kube-prometheus-stack-kube-proxy 92s |
| 99 | +kube-prometheus-stack-kube-scheduler 92s |
| 100 | +kube-prometheus-stack-kubelet 92s |
| 101 | +kube-prometheus-stack-prometheus 92s |
| 102 | +kube-state-metrics 92s |
| 103 | +node-exporter 92s |
| 104 | +prometheus-operator 92s |
| 105 | +``` |
| 106 | + |
| 107 | +Label selectors are used to map service monitor to kubernetes services. </br> |
| 108 | +That is how Prometheus is configured on what to scrape. |
| 109 | + |
| 110 | +As an example you can describe a service monitor: |
| 111 | + |
| 112 | +``` |
| 113 | +kubectl -n monitoring describe servicemonitor node-exporter |
| 114 | +``` |
| 115 | + |
| 116 | +# View Dashboards |
| 117 | + |
| 118 | +You can access the dashboards by using `port-forward` to access Grafana. |
| 119 | +It does not have a public endpoint for security reasons |
| 120 | + |
| 121 | +``` |
| 122 | +kubectl -n monitoring port-forward svc/grafana 3000:80 |
| 123 | +``` |
| 124 | + |
| 125 | +Then access Grafana on [localhost:3000](http://localhost:3000/) |
| 126 | + |
| 127 | + |
| 128 | +## Check Prometheus |
| 129 | + |
| 130 | +Similar to checking Grafana, we can also check Prometheus: |
| 131 | + |
| 132 | +``` |
| 133 | +kubectl -n monitoring port-forward svc/prometheus-operated 9090 |
| 134 | +``` |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
0 commit comments