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
mermaid
`
$1
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
$1
First, let's create an EKS cluster using eksctl:
` 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
bash
`Create EKS cluster
$1
ArgoCD is a declarative continuous delivery tool for Kubernetes. Let's install it:
` kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=argocd-server -n argocd
bash
`Create ArgoCD namespace
Install ArgoCD
Wait for pods to be ready
$1
Get the initial admin password and set up port forwarding:
` ARGOCD_PASSWORD=$(kubectl -n argocd get secret argocd-initial-admin-secret -o name)
echo $ARGOCD_PASSWORD | base64 -d kubectl get secret argocd-initial-admin-secret -n argocd -o yaml kubectl port-forward svc/argocd-server -n argocd 8080:443
bash
`Get the initial admin password
Alternative method - get the secret in YAML format
Port forward ArgoCD server
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
$1
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
mermaid
`
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
:
`yaml
`
Example service.yaml apiVersion: v1
kind: Service
metadata:
name: sample-app
spec:
selector:
app: sample-app
ports:
- port: 80
targetPort: 80
type: LoadBalancer
:
`yaml
`
$1
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
yaml
`
$1
` 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
mermaid
``
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
$1
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
$1
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
$1
After mastering the basics, explore:
1. Multi-cluster management
2. Canary deployments
3. Progressive delivery
4. Custom health checks
5. Integration with CI pipelines
$1
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.
$1
1. [ArgoCD Documentation](https://argo-cd.readthedocs.io/)
2. [AWS EKS Workshop](https://www.eksworkshop.com/)
3. [GitOps Best Practices](https://www.weave.works/technologies/gitops/)
4. [Kubernetes Documentation](https://kubernetes.io/docs/)
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.