Skip to content

Commit f984221

Browse files
feat(video): Monitoring with Prometheus and Kubernets
1 parent 04c12aa commit f984221

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
layout: post
3+
title: "Monitoring & Beautiful Dashboards with Grafana and Prometheus on Kubernetes"
4+
date: 2022-07-23 10:00:00 -0500
5+
categories: kubernetes
6+
tags: kubernetes grafana prometheus alert-manager k3s
7+
---
8+
9+
[![Beautiful Dashboards & Monitoring - Grafana and Prometheus Kubernetes Tutorial](https://img.youtube.com/vi/fzny5uUaAeY/0.jpg)](https://www.youtube.com/watch?v=fzny5uUaAeY "Beautiful Dashboards & Monitoring - Grafana and Prometheus Kubernetes Tutorial")
10+
11+
If I could start my HomeLab all over, what would I choose? Would I choose the same servers, rack, networking, gateway, switch, firewall, my pc conversion, and even my disk shelf NAS? Did I make a good choice or a bad one? Join me as we give each piece of my HomeLab a Keep or Upgrade rating.
12+
13+
📺 [Watch Video](https://www.youtube.com/watch?v=fzny5uUaAeY)
14+
15+
A HUGE thanks to Datree for sponsoring this video!
16+
17+
Combat misconfigurations. Empower engineers.
18+
19+
<https://www.datree.io>
20+
21+
## Getting Started
22+
23+
If you need to install a new kubernetes cluster you can use my [Ansible Playbook](https://docs.technotim.live/posts/k3s-etcd-ansible/) to install one.
24+
25+
### k3s
26+
27+
If you want to get metrics from your k3s servers, you will need to provide some additional flags to k3s.
28+
29+
Additional k3s flags used in the video:
30+
31+
```yml
32+
extra_server_args: "--no-deploy servicelb --no-deploy traefik --kube-controller-manager-arg bind-address=0.0.0.0 --kube-proxy-arg metrics-bind-address=0.0.0.0 --kube-scheduler-arg bind-address=0.0.0.0 --etcd-expose-metrics true --kubelet-arg containerd=/run/k3s/containerd/containerd.sock"
33+
```
34+
35+
### helm
36+
37+
```bash
38+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
39+
chmod 700 get_helm.sh
40+
./get_helm.sh
41+
```
42+
43+
Install helm
44+
45+
The helm chart we will be using to install Grafana, Preometheus, and Alert Manager is [kube-prometheus-stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack)
46+
47+
## Installing
48+
49+
Verify you can communicate with your cluster
50+
51+
```bash
52+
kubectl get nodes
53+
```
54+
55+
```console
56+
NAME STATUS ROLES AGE VERSION
57+
k3s-01 Ready control-plane,etcd,master 10h v1.23.4+k3s1
58+
k3s-02 Ready control-plane,etcd,master 10h v1.23.4+k3s1
59+
k3s-03 Ready control-plane,etcd,master 10h v1.23.4+k3s1
60+
k3s-04 Ready <none> 10h v1.23.4+k3s1
61+
k3s-05 Ready <none> 10h v1.23.4+k3s1
62+
```
63+
64+
Verify helm is installed
65+
66+
```bash
67+
helm version
68+
```
69+
70+
```console
71+
version.BuildInfo{Version:"v3.8.0", GitCommit:"d14138609b01886f544b2025f5000351c9eb092e", GitTreeState:"clean", GoVersion:"go1.17.5"}
72+
```
73+
74+
Add helm repo
75+
76+
```bash
77+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
78+
```
79+
80+
Update repo
81+
82+
```bash
83+
helm repo update
84+
85+
```
86+
87+
Create a Kubernetes Namespace
88+
89+
```bash
90+
kubectl create namespace monitoring
91+
```
92+
93+
Echo username and password to a file
94+
95+
```bash
96+
echo -n 'adminuser' > ./admin-user # change your username
97+
echo -n 'p@ssword!' > ./admin-password # change your password
98+
```
99+
100+
Create a Kubernetes Secret
101+
102+
```bash
103+
kubectl create secret generic grafana-admin-credentials --from-file=./admin-user --from-file=admin-password -n monitoring
104+
```
105+
106+
You should see
107+
108+
```console
109+
secret/grafana-admin-credentials created
110+
```
111+
112+
Verify your secret
113+
114+
```bash
115+
kubectl describe secret -n monitoring grafana-admin-credentials
116+
```
117+
118+
You should see
119+
120+
```console
121+
Name: grafana-admin-credentials
122+
Namespace: monitoring
123+
Labels: <none>
124+
Annotations: <none>
125+
126+
Type: Opaque
127+
128+
Data
129+
====
130+
admin-password: 9 bytes
131+
admin-user: 9 bytes
132+
```
133+
134+
Verify the username
135+
136+
```bash
137+
kubectl get secret -n monitoring grafana-admin-credentials -o jsonpath="{.data.admin-user}" | base64 --decode
138+
```
139+
140+
You should see
141+
142+
```console
143+
adminuser%
144+
```
145+
146+
Verify password
147+
148+
```bash
149+
kubectl get secret -n monitoring grafana-admin-credentials -o jsonpath="{.data.admin-password}" | base64 --decode
150+
```
151+
152+
```console
153+
p@ssword!%
154+
```
155+
156+
Remove username and password file from filesystem
157+
158+
```bash
159+
rm admin-user && rm admin-password
160+
```
161+
162+
Create a values file to hold our helm values
163+
164+
```bash
165+
nano values.yml
166+
```
167+
168+
paste in values from [here](https://github.com/techno-tim/launchpad/tree/master/kubernetes/kube-prometheus-stack)
169+
170+
Create our kube-prometheus-stack
171+
172+
```bash
173+
helm install -n monitoring prometheus prometheus-community/kube-prometheus-stack -f values.yaml
174+
```
175+
176+
Port Forwarding Grafana UI
177+
178+
(be sure to change the pod name to one that matches yours)
179+
180+
```bash
181+
kubectl port-forward -n monitoring grafana-fcc55c57f-fhjfr 52222:3000
182+
```
183+
184+
Visit Grafana
185+
186+
<http://localhost:52222>
187+
188+
Examples:
189+
190+
[Traefik Ingress example](https://github.com/techno-tim/launchpad/tree/master/kubernetes/kube-prometheus-stack)
191+
192+
## Links
193+
194+
⚙️ See all the hardware I recommend at <https://l.technotim.live/gear>
195+
196+
🚀 Don't forget to check out the [🚀Launchpad repo](https://l.technotim.live/quick-start) with all of the quick start source files

0 commit comments

Comments
 (0)