
Introduction
In modern DevOps workflows, Infrastructure as Code (IaC) and GitOps practices streamline software delivery. AWS EKS (Elastic Kubernetes Service) provides a managed Kubernetes cluster, while Terraform automates infrastructure provisioning. ArgoCD enables declarative, continuous delivery using Git repositories.
In this guide, we’ll:
✅ Provision an EKS cluster with Terraform✅ Containerize a sample application using Docker✅ Push the image to Amazon ECR (Elastic Container Registry)✅ Deploy the app to Kubernetes using ArgoCD & GitLab CI/CD✅ Implement GitOps for automatic deployments
🚀 Architecture Overview
The workflow consists of the following steps:
1️⃣ Terraform provisions AWS infrastructure (VPC, EKS, IAM roles, security groups)2️⃣ Docker builds & pushes a containerized app to AWS ECR3️⃣ Kubernetes manifests are stored in GitLab and deployed via ArgoCD4️⃣ GitLab CI/CD automates testing and deployment
1️⃣ Provisioning AWS EKS with Terraform
Step 1: Install Prerequisites
Ensure you have the following installed:
- Terraform (>=1.5.0)
- AWS CLI (
aws configure) - Kubectl (
eksctl install) - Helm (
helm install) - ArgoCD CLI (
argocd)
Step 2: Create Terraform Configuration for EKS
main.tf - Define the EKS cluster:
provider "aws" {
region = "us-east-1"
}
resource "aws_eks_cluster" "my_eks" {
name = "my-cluster"
role_arn = aws_iam_role.eks_cluster_role.arn
vpc_config {
subnet_ids = [aws_subnet.public_1.id, aws_subnet.public_2.id]
}
}
Apply Terraform Configuration:
terraform init
terraform apply -auto-approve
Verify the cluster:
aws eks --region us-east-1 update-kubeconfig --name my-cluster
kubectl get nodes
2️⃣ Build and Push Docker Image to Amazon ECR
aws ecr create-repository --repository-name my-app
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account_id>.dkr.ecr.us-east-1.amazonaws.com
docker build -t my-app .
docker tag my-app:latest <account_id>.dkr.ecr.us-east-1.amazonaws.com/my-app:latest
docker push <account_id>.dkr.ecr.us-east-1.amazonaws.com/my-app:latest
3️⃣ Deploying to Kubernetes with ArgoCD
Step 1: Install ArgoCD in EKS
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Step 2: Configure ArgoCD
Expose ArgoCD server:
kubectl port-forward svc/argocd-server -n argocd 8080:443
Login:
argocd login localhost:8080 --username admin --password <initial-password>
Step 3: Deploy Application with ArgoCD
application.yaml - Define ArgoCD application:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
destination:
namespace: default
server: https://kubernetes.default.svc
source:
repoURL: "https://gitlab.com/my-repo.git"
targetRevision: main
path: manifests/
syncPolicy:
automated:
prune: true
selfHeal: true
Apply the application:
kubectl apply -f application.yaml
4️⃣ Automating with GitLab CI/CD
.gitlab-ci.yml - Define CI/CD pipeline:
stages:
- build
- deploy
docker-build:
stage: build
script:
- docker build -t <account_id>.dkr.ecr.us-east-1.amazonaws.com/my-app:latest .
- docker push <account_id>.dkr.ecr.us-east-1.amazonaws.com/my-app:latest
deploy:
stage: deploy
script:
- kubectl apply -f deployment.yaml
🚀 Best Practices
✅ Use Terraform remote state with S3 + DynamoDB✅ Implement secrets management with AWS Secrets Manager✅ Use Helm charts for better Kubernetes deployments✅ Implement ArgoCD ApplicationSets for multi-cluster deployments✅ Integrate AWS CloudWatch for monitoring
❓ FAQs
1️⃣ How do I update my app after changes?
- Push changes to the repository, and ArgoCD will automatically sync and deploy.
2️⃣ How do I rollback a deployment?
argocd app rollback my-app 1
3️⃣ Can I integrate AWS ALB with EKS?
- Yes! Use the AWS ALB Ingress Controller.
4️⃣ How do I monitor the application?
- Use AWS CloudWatch and
kubectl logs -f <pod-name>for debugging.
Share your thoughts below! 👇
📢 Have questions or feedback? Drop a comment below or connect with me on Twitter/X@spysood!
Originally published on Medium.