GitOps in Action: Deploying Flask with GitHub Actions, Helm, and ArgoCD

Listen to this Post

GitOps simplifies Kubernetes deployments by using a Git repository as the single source of truth. This approach ensures consistency, traceability, and control over infrastructure changes. Below, we explore a practical implementation using ArgoCD, Helm, and GitHub Actions to deploy a Flask application.

Key Components

  1. ArgoCD: A GitOps operator that syncs Kubernetes manifests from Git to your cluster.
  2. Helm: A package manager for Kubernetes, enabling templatized deployments.
  3. GitHub Actions: Automates CI/CD workflows triggered by Git events.

You Should Know: Practical Steps & Code

1. Set Up ArgoCD in Your Cluster

Install ArgoCD using the following commands:

kubectl create namespace argocd 
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml 

Access the ArgoCD UI:

kubectl port-forward svc/argocd-server -n argocd 8080:443 

Login with the default admin password:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d 

2. Define Helm Charts for Flask App

Create a Helm chart structure:

helm create flask-app 
cd flask-app 

Modify `values.yaml` to configure your Flask deployment:

replicaCount: 2 
image: 
repository: your-docker-repo/flask-app 
tag: latest 
service: 
type: ClusterIP 
port: 5000 

3. Configure GitHub Actions for CI/CD

Create `.github/workflows/deploy.yaml`:

name: Deploy to Kubernetes 
on: 
push: 
branches: [ main ] 
jobs: 
deploy: 
runs-on: ubuntu-latest 
steps: 
- uses: actions/checkout@v2 
- name: Install Helm 
run: | 
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 
chmod 700 get_helm.sh 
./get_helm.sh 
- name: Deploy via ArgoCD 
run: | 
helm package flask-app 
git config --global user.name "GitHub Actions" 
git config --global user.email "[email protected]" 
git add . 
git commit -m "Update Helm chart" 
git push 

4. Sync ArgoCD with Your Git Repo

In the ArgoCD UI, add your repository and create an Application:
– Repository URL: Your Git repo
– Path: `flask-app` (Helm chart dir)
– Destination Cluster: Your Kubernetes cluster

What Undercode Say

GitOps streamlines Kubernetes management by enforcing Git-based workflows. Key takeaways:
– Auditability: Every change is tracked via Git commits.
– Automation: GitHub Actions + ArgoCD reduce manual intervention.
– Security: Prevent configuration drift with Git as the source of truth.

Essential Commands for GitOps Workflow:

 Check ArgoCD sync status 
argocd app get flask-app

Rollback a Helm release 
helm rollback flask-app 1

Debug Kubernetes deployments 
kubectl logs -l app=flask-app 
kubectl describe pod flask-app-xyz 

Expected Output:

A fully automated GitOps pipeline deploying Flask apps with Helm, ArgoCD, and GitHub Actions.

Reference:

GitOps in Action: Deploying Flask with GitHub Actions, Helm, and ArgoCD

References:

Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image