This repo contains the Terraform project to automate VPC + Elatic Kubernetes Cluster (EKS) deployment on AWS and setting up monitoring via Prometheus and Grafana stack using Helm Charts.
- vpc.tf : For creating Virtual Private Cloud in AWS
- eks.tf : For creating EKS Cluster
- terraform.tfvars : Terraform variables for VPC (use your own)
- k8s-config.yaml : Deployment for our Node App, Internal Service and ServiceMonitor that expose /metrics endpoint to Prometheus
- prometheus-node app : source code for our node application along with Dockerfile to build the image
- Terraform
- Helm Charts
- Docker
- Kubernetes
- Prometheus
- Grafana
Make sure you have Terraform installed on your machine and AWS CLI and Credentials configured. Navigate to the project root directory and follow the steps below"
terraform init
terraform plan
terraform apply -var-file terraform.tfvars
terraform destroy -target aws_vpc.myapp-vpc
terraform destroy
terraform state list
terraform state show aws_vpc.myapp-vpc
export TF_VAR_avail_zone="ap-south-1"
export TF_LOG=TRACE
The folder prometheus-node contains a Node.js that utilizes package to expose metrics on /metrics endpoint and supports histogram, summaries, gauges and counters for the application stats.
Note: A public image for this node app is already created and available as 977977/node-prometheus. If you want to build and push it yourself, navigate to prometheus-node and run the following command:
docker build -t repo-name/image-name:image-tag .
docker push repo-name/image-name:image-tag
Make sure you have Helm installed on your machine.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
aws eks update-kubeconfig --name ava-eks-cluster --region ap-south-1
kubectl create namespace monitoring-prom
helm install monitoring prometheus-community/kube-prometheus-stack -n monitoring-prom
helm ls -n monitoring-prom
kubectl get all -n monitoring-prom
kubectl apply -f nginx-deployment-config.yaml
kubectl port-forward svc/monitoring-kube-prometheus-prometheus 9090:9090 -n monitoring-prom &
kubectl port-forward svc/monitoring-grafana 8080:80 -n monitoring &
user: admin
pwd: prom-operator
Go to EC2->LoadBalanancers->DNS. Click the endpoint to access Nginx server
or use:
kubectl port-forward svc/nodeappp 3000:3000
Contributions are highly welcomed. Please send a Pull Request with suggested changes or open an Issue to get things started! Feel free to tag @sagar-uprety in the issues :)