How to Implement GitOps with AWS EKS and ArgoCD
Learn how to set up a GitOps workflow using AWS EKS and ArgoCD for automated Kubernetes deployments and configuration management.
How to Implement GitOps with AWS EKS and ArgoCD
GitOps is a modern approach to managing Kubernetes configurations using Git as the single source of truth. This beginner-friendly guide will walk you through implementing GitOps practices with Amazon EKS (Elastic Kubernetes Service) using ArgoCD.
Prerequisites
Before we begin, make sure you have:
- An AWS account with appropriate permissions
- AWS CLI installed and configured
- kubectl installed
- helm installed
- A GitHub/GitLab account
Step 1: Setting up Amazon EKS
First, let's create an EKS cluster using eksctl:
# Create EKS cluster eksctl create cluster \ --name my-gitops-cluster \ --region us-west-2 \ --version 1.27 \ --nodegroup-name standard-workers \ --node-type t3.medium \ --nodes 2 \ --nodes-min 1 \ --nodes-max 3
Step 2: Installing ArgoCD
ArgoCD is a declarative continuous delivery tool for Kubernetes. Let's install it:
# Create ArgoCD namespace kubectl create namespace argocd # Install ArgoCD kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml # Wait for pods to be ready kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=argocd-server -n argocd
Step 3: Accessing ArgoCD UI
Get the initial admin password and set up port forwarding:
# Get the initial admin password ARGOCD_PASSWORD=$(kubectl -n argocd get secret argocd-initial-admin-secret -o name) echo $ARGOCD_PASSWORD | base64 -d # Alternative method - get the secret in YAML format kubectl get secret argocd-initial-admin-secret -n argocd -o yaml # Port forward ArgoCD server kubectl port-forward svc/argocd-server -n argocd 8080:443
The default username is 'admin'. For the password, use either of the above commands and decode the base64 value from the 'password' field.
Now you can access the ArgoCD UI at http://localhost:8080
Step 4: Creating a Sample Application
Let's create a simple application to demonstrate GitOps:
Create a new repository with the following structure:
my-gitops-app/ ├── base/ │ ├── deployment.yaml │ ├── service.yaml │ └── kustomization.yaml └── overlays/ ├── dev/ │ └── kustomization.yaml └── prod/ └── kustomization.yaml
Example
deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: sample-app spec: replicas: 2 selector: matchLabels: app: sample-app template: metadata: labels: app: sample-app spec: containers: - name: nginx image: nginx:1.21 ports: - containerPort: 80
Example
service.yaml
apiVersion: v1 kind: Service metadata: name: sample-app spec: selector: app: sample-app ports: - port: 80 targetPort: 80 type: LoadBalancer
Step 5: Configuring ArgoCD Application
Create an ArgoCD application to track your repository:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: sample-app namespace: argocd spec: project: default source: repoURL: https://github.com/yourusername/my-gitops-app.git targetRevision: HEAD path: overlays/dev destination: server: https://kubernetes.default.svc namespace: default syncPolicy: automated: prune: true selfHeal: true
Step 6: GitOps Workflow
The GitOps workflow follows these steps:
- Developers make changes to the Git repository
- ArgoCD detects changes in the repository
- ArgoCD pulls the latest changes
- Changes are automatically applied to the cluster
- ArgoCD ensures the desired state matches the actual state
Best Practices
-
Repository Structure
- Use separate repositories for application code and configurations
- Implement clear folder structure for different environments
- Use Kustomize or Helm for managing variations
-
Security
- Use HTTPS/SSH for Git repositories
- Implement RBAC in ArgoCD
- Regularly rotate credentials
- Scan manifests for security issues
-
Monitoring
- Set up alerts for sync failures
- Monitor application health
- Track deployment frequency
- Set up logging
Troubleshooting Guide
Common issues and solutions:
-
Sync Failures
- Check Git repository accessibility
- Verify YAML syntax
- Check ArgoCD logs
- Verify cluster permissions
-
Application Health Issues
- Check pod logs
- Verify resource requirements
- Check network policies
- Validate service configurations
Next Steps
After mastering the basics, explore:
- Multi-cluster management
- Canary deployments
- Progressive delivery
- Custom health checks
- Integration with CI pipelines
Conclusion
GitOps with AWS EKS and ArgoCD provides a powerful way to manage Kubernetes applications. By following this guide, you've learned the fundamentals of implementing GitOps practices in your organization.