# Hands-On: Deploying Prometheus on Kubernetes

Follow these steps to deploy Prometheus in an Amazon EKS cluster using the **kube-prometheus-stack** Helm chart.

### **Step 1: Create an EKS Cluster**

#### **Prerequisites**

* Install the **AWS CLI**, and configure it using `aws configure`. [AWS CLI Installation Guide](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
    
* Install **eksctl** and **kubectl**. [EKSCTL Guide](https://eksctl.io/installation/) | [Kubectl Guide](https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html)
    

#### **Commands to Create the Cluster**

```python
eksctl create cluster --name observability \
                      --region us-east-1 \
                      --zones us-east-1a,us-east-1b \
                      --without-nodegroup
```

```python
eksctl utils associate-iam-oidc-provider \
    --region us-east-1 \
    --cluster observability \
    --approve
```

```python
eksctl create nodegroup --cluster observability \
                        --region us-east-1 \
                        --name observability-ng-private \
                        --node-type t3.medium \
                        --nodes-min 2 \
                        --nodes-max 3 \
                        --node-volume-size 20 \
                        --managed \
                        --node-private-networking
```

Update your `kubeconfig` file to interact with the cluster:

```python
aws eks update-kubeconfig --name observability
```

---

### **Step 2: Install Kube-Prometheus-Stack**

Add the Prometheus Helm chart repository:

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

Create a dedicated namespace for monitoring:

```python
kubectl create ns monitoring
```

Install the Helm chart:

```python
helm install monitoring prometheus-community/kube-prometheus-stack \
-n monitoring \
-f ./custom_kube_prometheus_stack.yml
```

---

### **Step 3: Verify the Installation**

Check if the resources are running:

```python
kubectl get all -n monitoring
```

#### **Access Prometheus UI**

Forward Prometheus service to your local machine:

```python
kubectl port-forward service/prometheus-operated -n monitoring 9090:9090
```

Visit `http://localhost:9090`.

#### **Access Grafana UI**

Grafana credentials: username `admin`, password `prom-operator`.

```python
kubectl port-forward service/monitoring-grafana -n monitoring 8080:80
```

Visit `http://localhost:8080`.  
  
**Alertmanager UI**:

```python
kubectl port-forward service/alertmanager-operated -n monitoring 9093:9093
```

Visit `http://localhost:`9093

---

### **Step 4: Cleanup**

To remove the setup:

* Uninstall the Helm chart:
    

```python
helm uninstall monitoring -n monitoring
```

* Delete the namespace:
    

```python
kubectl delete ns monitoring
```

* Delete the EKS cluster:
    

```python
eksctl delete cluster --name observability
```

---

## **Conclusion**

Prometheus is a powerful tool for monitoring modern cloud-native systems, offering flexibility and integration with dynamic environments like Kubernetes. With Grafana, you can create stunning visualizations and dashboards to keep your infrastructure healthy and performant.

By following the steps in this blog, you now have a hands-on understanding of how to deploy and manage Prometheus on EKS. Monitoring your applications has never been easier!
