How to Implement GitOps with AWS EKS and ArgoCD
AWS

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.

March 12, 2024
DevHub Team
4 min read

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.

 

graph TB subgraph Developer["Developer Workflow"] Git["Git Repository"] --> |Push Changes| GH["GitHub/GitLab"] end subgraph AWS["AWS Cloud"] subgraph EKS["Amazon EKS"] ArgoCD["ArgoCD"] --> |Pull & Apply| K8s["Kubernetes Resources"] end end GH --> |Monitor Changes| ArgoCD style Git fill:#f96,stroke:#333,stroke-width:2px style GH fill:#333,stroke:#333,stroke-width:2px,color:#fff style ArgoCD fill:#FF9900,stroke:#232F3E,color:#232F3E style K8s fill:#326CE5,stroke:#fff,color:#fff style EKS fill:#FF9900,stroke:#232F3E,color:#232F3E

 

Prerequisites

Before we begin, make sure you have:

  1. An AWS account with appropriate permissions
  2. AWS CLI installed and configured
  3. kubectl installed
  4. helm installed
  5. 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:

 

graph LR subgraph "Application Structure" direction TB App["Sample App"] --> |Contains| D[Deployment] App --> |Contains| S[Service] App --> |Contains| CM[ConfigMap] end style App fill:#FF9900,stroke:#232F3E,color:#232F3E style D fill:#326CE5,stroke:#fff,color:#fff style S fill:#326CE5,stroke:#fff,color:#fff style CM fill:#326CE5,stroke:#fff,color:#fff

 

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

 

sequenceDiagram participant Dev as Developer participant Git as Git Repository participant Argo as ArgoCD participant K8s as Kubernetes Dev->>Git: Push changes Git-->>Argo: Detect changes Argo->>Git: Pull changes Argo->>K8s: Apply changes K8s-->>Argo: Report status Argo-->>Git: Update status

 

The GitOps workflow follows these steps:

  1. Developers make changes to the Git repository
  2. ArgoCD detects changes in the repository
  3. ArgoCD pulls the latest changes
  4. Changes are automatically applied to the cluster
  5. ArgoCD ensures the desired state matches the actual state

Best Practices

  1. Repository Structure

    • Use separate repositories for application code and configurations
    • Implement clear folder structure for different environments
    • Use Kustomize or Helm for managing variations
  2. Security

    • Use HTTPS/SSH for Git repositories
    • Implement RBAC in ArgoCD
    • Regularly rotate credentials
    • Scan manifests for security issues
  3. Monitoring

    • Set up alerts for sync failures
    • Monitor application health
    • Track deployment frequency
    • Set up logging

Troubleshooting Guide

Common issues and solutions:

  1. Sync Failures

    • Check Git repository accessibility
    • Verify YAML syntax
    • Check ArgoCD logs
    • Verify cluster permissions
  2. Application Health Issues

    • Check pod logs
    • Verify resource requirements
    • Check network policies
    • Validate service configurations

Next Steps

After mastering the basics, explore:

  1. Multi-cluster management
  2. Canary deployments
  3. Progressive delivery
  4. Custom health checks
  5. 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.

Additional Resources

  1. ArgoCD Documentation
  2. AWS EKS Workshop
  3. GitOps Best Practices
  4. Kubernetes Documentation
AWS
EKS
GitOps
ArgoCD
Kubernetes