This repository is designed to automate infrastructure deployment and management using Terraform and CI/CD pipelines. The primary goals are:
- Ensure consistent infrastructure provisioning.
- Enable easy scaling and modification of infrastructure.
- Automate deployment using CI/CD for increased efficiency and reduced human error.
- Centralize infrastructure state and configurations for better traceability.
The infrastructure is defined using Terraform to provision and manage the following resources:
- Creates an Elastic Kubernetes Service (EKS) cluster for running containerized applications.
- Configures control plane, API server, and network settings.
- Sets up IAM roles for managing access to the cluster.
- Provisions managed node groups for running workloads within the EKS cluster.
- Supports auto-scaling based on resource usage.
- Configures instance types, disk size, and scaling policies.
- Creates IAM roles for the Kubernetes control plane, worker nodes, and service accounts.
- Configures least-privilege permissions for enhanced security.
- Provisions a Virtual Private Cloud (VPC) for isolating Kubernetes resources.
- Configures public and private subnets for secure network architecture.
- Sets up security groups and network access rules.
- Defines storage classes and persistent volumes for application data.
- Supports dynamic provisioning of EBS volumes.
- Provides external access to Kubernetes services using HTTP and HTTPS.
- Enables traffic routing based on host and path-based rules.
- Ensures secure communication using TLS.
- Prometheus collects and stores real-time metrics from Kubernetes components and applications.
- Grafana provides a user-friendly interface for visualizing metrics and creating dashboards.
- Alertmanager handles alerts based on Prometheus metrics for proactive issue resolution.
This repository contains infrastructure as code (IaC) for managing cloud-based infrastructure using Terraform. It includes buildspec files for CI/CD automation and Terraform configurations for the development environment.
Infrastructure/
├── tf-Infra/
│ ├── buildspec/
│ │ ├── apply-buildspec.yaml
│ │ ├── destroy-buildspec.yaml
│ │ └── plan-buildspec.yaml
│ └── dev/
│ ├── backend.tf
│ ├── cluster.tf
│ ├── iam.tf
│ ├── main.tf
│ ├── node-group.tf
│ ├── outputs.tf
│ ├── providers.tf
│ ├── terraform.tfvars
│ ├── variables.tf
│ └── versions.tf
├── tf-modules/
│ ├── modules/
│ │ ├── eks-managed-node-group/
│ │ ├── fargate-profile/
│ │ └── self-managed-node-group/
│ └── templates/
└── README.md
The buildspec files are used for automating infrastructure deployment, changes, and destruction using CI/CD pipelines:
- Executes
terraform applycommand to create or update infrastructure. - References the Terraform state file to track changes.
- Executes
terraform destroycommand to tear down infrastructure resources. - Ensures that all dependencies are properly handled during cleanup.
- Executes
terraform plancommand to generate an execution plan. - Highlights infrastructure changes before applying them.
The dev folder contains Terraform configuration files to define and manage the development environment:
- Configures the remote backend for storing Terraform state (e.g., S3, Azure Storage).
- Defines the Kubernetes cluster resources such as control plane, networking, and DNS.
- Manages AWS Identity and Access Management (IAM) roles and permissions.
- Primary configuration file that references other modules and components.
- Defines the node groups for the Kubernetes cluster (including auto-scaling and instance types).
- Captures output values after deployment (e.g., cluster endpoint, node details).
- Configures Terraform providers such as AWS, Azure, etc.
- Contains environment-specific variables (e.g., region, instance size).
- Defines input variables for the Terraform configuration.
- Specifies the Terraform and provider versions to ensure compatibility.
The tf-modules folder contains reusable Terraform modules:
- Configures EKS node groups managed by AWS.
- Sets up Kubernetes workloads on AWS Fargate (serverless).
- Configures custom-managed node groups for greater control.
The templates folder contains user data templates used for bootstrapping nodes:
- aws_auth_cm.tpl – AWS authentication configuration template.
- bottlerocket_user_data.tpl – User data template for Bottlerocket nodes.
- linux_user_data.tpl – User data template for Linux-based nodes.
- windows_user_data.tpl – User data template for Windows-based nodes.
-
Plan – Generate a plan using
plan-buildspec.yaml:terraform plan
-
Apply – Deploy the infrastructure using
apply-buildspec.yaml:terraform apply
-
Destroy – Clean up resources using
destroy-buildspec.yaml:terraform destroy
- Use separate state files for different environments (e.g., dev, stage, prod).
- Enable remote state locking to avoid conflicts.
- Always review the
terraform planoutput before applying changes. - Follow infrastructure as code (IaC) best practices, including modularization and state isolation.
- Ensure that Terraform backend configuration is properly set up in
backend.tf. - Make sure IAM roles and permissions are correctly assigned for deployment.
- Review logs after deployment to validate the infrastructure state.
The Infra-tools directory includes configurations for monitoring and alerting using Prometheus and Grafana.
- prometheus-windows-exporter – Prometheus exporter for monitoring Windows-based nodes.
- alertmanager – Configuration for handling alerts from Prometheus.
- grafana – Dashboard configurations for monitoring Kubernetes clusters.
- exporters – Exporter configurations for Kubernetes components like API Server, Scheduler, etc.
- thanos-ruler – Configuration for Thanos Ruler to extend Prometheus monitoring capabilities.
- Templates – Helm templates for setting up Prometheus, Grafana, and Alertmanager.
- ServiceMonitors – Define how Prometheus scrapes metrics from Kubernetes services.
- Rules – Alerting rules and recording rules for Prometheus.
- Ingress – Configuration for exposing monitoring services.
-
Install Prometheus using the provided Helm chart:
helm install prometheus ./Infra-tools/prometheus-chart
-
Access Grafana:
- Username/Password: Defined in the Grafana secret.
- Access URL:
http://<grafana-url>
-
View Metrics in Grafana:
- Use pre-configured dashboards for Kubernetes components.
The Infra-tools/ingress-nginx directory contains configurations for setting up NGINX as an ingress controller for Kubernetes.
- Controller – NGINX controller deployment for managing external access to services.
- Service – LoadBalancer or NodePort service configuration for exposing the NGINX controller.
- ConfigMap – Custom NGINX configurations (timeouts, buffering, etc.).
- TLS – Secure communication using TLS certificates.
-
Install NGINX Ingress Controller using Helm:
helm install ingress-nginx ./Infra-tools/ingress-nginx
-
Verify the deployment:
kubectl get pods -n ingress-nginx
-
Create an Ingress resource to expose services:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress namespace: default spec: rules: - host: example.com http: paths: - path: / pathType: Prefix backend: service: name: example-service port: number: 80
The Infra-tools/prometheus-chart directory includes configurations for setting up Prometheus and Grafana for monitoring and alerting.
- prometheus-windows-exporter – Prometheus exporter for monitoring Windows-based nodes.
- alertmanager – Configuration for handling alerts from Prometheus.
- grafana – Dashboard configurations for monitoring Kubernetes clusters.
- exporters – Exporter configurations for Kubernetes components like API Server, Scheduler, etc.
- thanos-ruler – Configuration for Thanos Ruler to extend Prometheus monitoring capabilities.
-
Install Prometheus using the provided Helm chart:
helm install prometheus ./Infra-tools/prometheus-chart
-
Access Grafana:
- Username/Password: Defined in the Grafana secret.
- Access URL:
http://<grafana-url>
-
View Metrics in Grafana:
- Use pre-configured dashboards for Kubernetes components.