feat(k8s): Add kubernetes dashboard

Use https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
This commit is contained in:
Rodney Osodo
2024-07-10 13:52:01 +03:00
parent e74f730d7a
commit 6fe026dac7
6 changed files with 4976 additions and 0 deletions
+43
View File
@@ -9,3 +9,46 @@ push-image:
.PHONY: run
run:
nameko run service:HTTPService --config config.yaml
.PHONY: install-prometheus-k8s
install-prometheus-k8s:
@echo "Installing Prometheus on k8s"
@kubectl create namespace monitoring
@helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
@helm repo update
@helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring -f values.yaml
@echo "Prometheus installed on k8s"
@echo "List of pods and services created by Prometheus on k8s"
kubectl get pods -n monitoring
kubectl get svc -n monitoring
@echo "Expose Prometheus service on k8s"
kubectl expose service prometheus-kube-prometheus-prometheus -n monitoring --type=NodePort --target-port=9090 --name=prometheus-kube-prometheus-prometheus-np
@echo "Prometheus service exposed on k8s"
kubectl get svc prometheus-kube-prometheus-prometheus-np -n monitoring
@echo "Expose Grafana service on k8s"
kubectl expose service prometheus-grafana -n monitoring --type=NodePort --target-port=3000 --name=prometheus-grafana-np
@echo "Grafana service exposed on k8s"
kubectl get svc prometheus-grafana-np -n monitoring
.PHONY: remove-prometheus-k8s
remove-prometheus-k8s:
@helm uninstall prometheus -n monitoring
@kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
@kubectl delete crd alertmanagers.monitoring.coreos.com
@kubectl delete crd podmonitors.monitoring.coreos.com
@kubectl delete crd probes.monitoring.coreos.com
@kubectl delete crd prometheusagents.monitoring.coreos.com
@kubectl delete crd prometheuses.monitoring.coreos.com
@kubectl delete crd prometheusrules.monitoring.coreos.com
@kubectl delete crd scrapeconfigs.monitoring.coreos.com
@kubectl delete crd servicemonitors.monitoring.coreos.com
@kubectl delete crd thanosrulers.monitoring.coreos.com
@kubectl delete namespace monitoring
.PHONY: deploy-to-k8s
deploy-to-k8s:
@kubectl apply -n nameko-prometheus -f k8s.yaml
.PHONY: remove-from-k8s
remove-from-k8s:
@kubectl delete -f k8s.yaml
+99
View File
@@ -25,3 +25,102 @@ for i in {1..100}; do curl -X GET http://localhost:8000/goodbye && curl -X GET h
```
You can access the Prometheus dashboard at `http://localhost:9090`.
## Kubernetes
You need to have a Kubernetes cluster running. You can use Minikube or Docker Desktop. Also, you need to have Helm installed.
Run
```bash
make install-prometheus-k8s
```
This command creates `monitoring` namespace, adds the Prometheus Helm [repository](https://prometheus-community.github.io/helm-charts), installs Prometheus, and exposes the Prometheus service.
You should see something like this:
```bash
Installing Prometheus on k8s
namespace/monitoring created
"prometheus-community" already exists with the same configuration, skipping
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "grafana" chart repository
...Successfully got an update from the "prometheus-community" chart repository
...Successfully got an update from the "ory" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
NAME: prometheus
LAST DEPLOYED: Wed Jul 10 13:41:15 2024
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
kubectl --namespace monitoring get pods -l "release=prometheus"
Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.
Prometheus installed on k8s
List of pods and services created by Prometheus on k8s
kubectl get pods -n monitoring
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-kube-prometheus-alertmanager-0 1/2 Running 0 8s
prometheus-grafana-5c7b44cc98-ms982 2/3 Running 0 11s
prometheus-kube-prometheus-operator-7dd887c879-8kzmr 1/1 Running 0 11s
prometheus-kube-state-metrics-84746dcf78-6dnm8 1/1 Running 0 11s
prometheus-prometheus-kube-prometheus-prometheus-0 1/2 Running 0 8s
prometheus-prometheus-node-exporter-gccqd 1/1 Running 0 11s
kubectl get svc -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 8s
prometheus-grafana ClusterIP 10.43.105.240 <none> 80/TCP 11s
prometheus-kube-prometheus-alertmanager ClusterIP 10.43.97.21 <none> 9093/TCP,8080/TCP 11s
prometheus-kube-prometheus-operator ClusterIP 10.43.224.94 <none> 443/TCP 11s
prometheus-kube-prometheus-prometheus ClusterIP 10.43.192.217 <none> 9090/TCP,8080/TCP 11s
prometheus-kube-state-metrics ClusterIP 10.43.27.193 <none> 8080/TCP 11s
prometheus-operated ClusterIP None <none> 9090/TCP 8s
prometheus-prometheus-node-exporter ClusterIP 10.43.206.103 <none> 9100/TCP 11s
Expose Prometheus service on k8s
kubectl expose service prometheus-kube-prometheus-prometheus -n monitoring --type=NodePort --target-port=9090 --name=prometheus-kube-prometheus-prometheus-np
service/prometheus-kube-prometheus-prometheus-np exposed
Prometheus service exposed on k8s
kubectl get svc prometheus-kube-prometheus-prometheus-np -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus-kube-prometheus-prometheus-np NodePort 10.43.164.40 <none> 9090:32243/TCP,8080:32496/TCP 0s
Expose Grafana service on k8s
kubectl expose service prometheus-grafana -n monitoring --type=NodePort --target-port=3000 --name=prometheus-grafana-np
service/prometheus-grafana-np exposed
Grafana service exposed on k8s
kubectl get svc prometheus-grafana-np -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus-grafana-np NodePort 10.43.8.145 <none> 80:30461/TCP 1s
```
Prometheus and grafana services are exported as NodePort. You can access the Prometheus dashboard or Grafana dashboard.
From the above output, you can see that Prometheus is exposed on port `32243` and Grafana is exposed on port `30461`.
> Grafana login username is `admin` and password is `prom-operator`.
### Deploy the services
Run the following command which deploys the services to Kubernetes:
```bash
make deploy-to-k8s
```
The services are exposed as NodePort.
Simulate network traffic:
```bash
for i in {1..1000}; do curl -X GET http://192.168.100.202:30081/goodbye &> /dev/null && curl -X GET http://192.168.100.202:30081/hello &> /dev/null; done
```
## Example Dashboards
![Cluster Information](./assets/cluster.png)
![Namespace Information](./assets/namespace.png)
Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

+58
View File
@@ -0,0 +1,58 @@
apiVersion: v1
kind: Namespace
metadata:
name: nameko-prometheus
labels:
name: nameko-prometheus
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: nameko-service
namespace: nameko-prometheus
labels:
name: nameko-prometheus
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nameko-service
namespace: nameko-prometheus
labels:
app: nameko-service
spec:
replicas: 3
selector:
matchLabels:
app: nameko-service
template:
metadata:
labels:
app: nameko-service
spec:
serviceAccountName: nameko-service
containers:
- name: nameko-service
image: gitea.rodneyosodo.com/rodneyosodo/nameko-prometheus:latest
ports:
- containerPort: 8000
protocol: TCP
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: nameko-service
namespace: nameko-prometheus
labels:
app: nameko-service
monitoring: prometheus
spec:
type: NodePort
ports:
- name: http
port: 8000
targetPort: 8000
nodePort: 30081
selector:
app: nameko-service
+4776
View File
File diff suppressed because it is too large Load Diff