creating a local monitoring environment with helm
Tags: monitoring, kubernetes, devops, tutorial
Published: 2021-01-25 20:56:22

#Introduction
In this post, that is actually documentation for myself, I'll guide you thru the deployment of a monitoring environment in your local machine, this can be used for study and prototype. The project will use prometheus to monitor and grafana to plot graphs.

#Getting your machine ready

I'm using Ubuntu 20.04.1 LTS as my OS

First you'll need to install a tool to run Kubernetes locally (kind, minikube, k3s or other that you like; Personally I use kind)

The steps are the following
```
$wget https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-linux-amd64
$chmod +x kind-linux-amd64
$mv kind-linux-amd64 /usr/local/bin/kind
$kind version
```
and then install Helm

```
sudo snap install helm --classic
```
for other ways of installing helm please refer to [Helm Documentation](https://helm.sh/docs/intro/install/)

#Kind

Now that we have our tools installed we need to create a kubernetes cluster 

`kind create cluster --name`

If you don't put the flag `--name` the cluster name will be "kind"

#Helm
Helm is a package manager for Kubernetes

To Add the prometheus charts repo use the command:

`helm repo add prometheus-community https://prometheus-community.github.io/helm-charts`

We'll install two helm charts

####kube-prometheus-stack

As per [github] (https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) This chart contains a collection of Kubernetes manifests, Grafana dashboards, and Prometheus rules combined with documentation and scripts to provide easy to operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus Operator.

`helm install prometheus-community/kube-prometheus-stack --generate-name`
####pushgateway

Pushgateway is a tool that pushes metrics that cannot be scraped

`helm install prometheus-community/prometheus-pushgateway --generate-name`

#Testing and Tweaking

Run `kubectl get services` to see the services running and some information about them. A detail when deploying prometheus localy is to change the type of the following services `kube-prometheus-stack-1611-operator` `kube-prometheus-stack-1611575778-grafana` from ClusterIP to NodePort (if you are deploying it in a cloud environment you shall change to LoadBalancer). More information about Kubernetes services can be found [here](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types)

To edit the services use the following command

`kubectl edit svc your-service-goes-here`

this command will open a vim type editor and allow you to edit information about the service

Now all you have to do is expose the ports using the port-forward command, the following example allows me to access alert-manager via browser

`kubectl port-forward svc/alertmanager-operated 9093`

The syntax is kubectl port-forward TYPE/NAME PORT.

And that's all for today :nerd_face:

#References
[Kube Prometheus Stack](https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack)
[Helm Documentation](https://helm.sh/docs/)
[Kind Quick Start](https://kind.sigs.k8s.io/docs/user/quick-start/)
[Pushgateway](https://prometheus.io/docs/practices/pushing/)
[Port Forward](https://kubernetesbyexample.com/pf/)
[Kubectl cheat sheet](https://kubernetes.io/pt/docs/reference/kubectl/cheatsheet/)