This is a WIP as I build out various pieces of the infrastructure. The goal of this infrastructure is to having a template I can apply to any of my future projects whenever it's time to deploy.
This project contain an application deployed on Google Cloud Platform (GCP). It integrates with Kubernetes (GKE) for container orchestration, Compute Engine for Prometheus and Grafana monitoring, and Terraform for infrastructure as code. The app is designed to provide insights into its operations using Prometheus for metrics collection and Grafana for visualization.
- Kubernetes Cluster (GKE): Hosts the application in a scalable and managed environment.
- Compute Engine: Runs Prometheus and Grafana for monitoring and visualization.
- Infrastructure as Code (Terraform): Automates the provisioning of all cloud resources.
- Networking (VPC): Configures separate subnets for GKE and Compute Engine instances for isolation.
- VPC Configuration
- Subnet-1: Dedicated for GKE.
- Subnet-2: Dedicated for Compute Engine.
- Compute Engine:
- Runs Prometheus and Grafana for monitoring.
- GKE Cluster:
- Hosts the application container.
- Tools Required:
- Terraform
- Google Cloud SDK
- Kubectl
- Ansible (for Compute Engine setup)
- GCP Requirements:
- Enabled APIs: Compute Engine, Kubernetes Engine, Artifact Registry.
- A billing-enabled project.
- Access:
- Admin permissions to create and manage resources.
git clone <repository-url>
cd <repository-folder>terraform initEdit terraform.tfvars to match your project setup:
project_id = "<your-project-id>"
region = "us-central1"
compute_zone = "us-central1-f"
compute_subnet_name = "subnet-2"
compute_subnet_cidr = "10.0.1.0/24"
gke_subnet_name = "subnet-1"
gke_subnet_cidr = "10.0.0.0/24"
vpc_name = "devops-vpc"
cluster_name = "devops-app-cluster"terraform apply- Update the
inventory/hostsfile with the Compute Engine public IP address. - Run the Ansible playbook:
ansible-playbook -i inventory/hosts playbooks/setup-prometheus-grafana.yml
- Build and push the application image:
docker build -t /:v1 . docker push /:v1
2. Apply Kubernetes deployment and service configurations:
```bash
kubectl apply -f kubernetes/devops-app-deployment.yaml
kubectl apply -f kubernetes/devops-app-service.yaml
- Verify the application is running:
kubectl get pods kubectl get services
- Access the application using the external IP of the service (LoadBalancer type). Use:
kubectl get services
- Prometheus:
http://<compute-engine-ip>:9090 - Grafana:
http://<compute-engine-ip>:3000
- Verify Terraform:
terraform plan
- Check Kubernetes Resources:
kubectl get all
- Validate Ansible Playbook:
ansible-playbook -i inventory/hosts playbooks/setup-prometheus-grafana.yml --check
- Debug Compute Engine:
- SSH into the instance:
gcloud compute ssh <instance-name> --zone <zone>
- Check Prometheus and Grafana logs.
- SSH into the instance:
To clean up all resources:
terraform destroy