Aws
AwsIntermediate

aws-eks-gitops

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.

 

``mermaid

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

`

 

$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:

`bash

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

`

$1

ArgoCD is a declarative continuous delivery tool for Kubernetes. Let's install it:

`bash

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

`

$1

Get the initial admin password and set up port forwarding:

`bash

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

$1

Let's create a simple application to demonstrate GitOps:

 

`mermaid

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:

`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:

`yaml

apiVersion: v1

kind: Service

metadata:

name: sample-app

spec:

selector:

app: sample-app

ports:

- port: 80

targetPort: 80

type: LoadBalancer

`

$1

Create an ArgoCD application to track your repository:

`yaml

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

`

$1

 

`mermaid

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

$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.