Day 11: Introduction to GitOps with ArgoCD
Welcome to Day 11 of the Zero to Platform Engineer in 30 Days challenge! 🚀 Today, we’re diving into GitOps, a modern approach to managing Kubernetes applications declaratively, with ArgoCD as our tool of choice.
By the end of this session, you’ll understand:
- What GitOps is and why it’s transformative for managing Kubernetes.
- How to use ArgoCD to implement GitOps.
- Hands-on steps to set up and deploy applications with ArgoCD.
What Is GitOps?
GitOps is a DevOps practice that uses Git repositories as the single source of truth for defining and managing infrastructure and applications. All changes to your Kubernetes environment are made via Git commits, which are automatically synced with your cluster.
Key Principles of GitOps
- Declarative: Infrastructure and application configurations are written as code.
- Version Controlled: All changes are tracked in Git, providing a clear history.
- Continuous Reconciliation: Tools like ArgoCD continuously compare the desired state in Git with the actual state in the cluster and reconcile any differences. Automation: Deployments and rollbacks are automated via Git commits.
🎯 Why GitOps Matters:
- Enables rapid recovery by simply reverting a Git commit.
- Improves collaboration by allowing pull requests for changes.
- Ensures cluster configurations are always auditable.
What Is ArgoCD?
ArgoCD is a declarative, Kubernetes-native continuous delivery tool that automates application deployments using GitOps principles.
Why Use ArgoCD?
- Visual Management: A web UI to monitor application health and sync status.
- Multi-Cluster Support: Manage multiple Kubernetes clusters from one place.
Hands-On: Setting Up GitOps with ArgoCD
Step 1: Install ArgoCD
- Create the argocd namespace:
kubectl create namespace argocd
- Install ArgoCD in your Kubernetes cluster:
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
- Verify that ArgoCD is installed:
kubectl get pods -n argocd
Step 2: Access the ArgoCD UI
- Expose the ArgoCD server:
kubectl port-forward svc/argocd-server -n argocd 8080:443
- Retrieve the admin password:
kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d
- Open the UI at https://localhost:8080 and log in with:
Username: admin
Password: Retrieved from the previous command.
Step 3: Deploy a Sample Application Using ArgoCD
- Add a sample application to Git:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
- Create an ArgoCD application linked to the Git repository:
argocd app create nginx-app \
--repo https://github.com/your-repo/sample-app.git \
--path ./k8s \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
- Sync the application:
argocd app sync nginx-app
- Verify the deployment:
kubectl get all -n default
Step 4: Automate Syncing
Enable auto-syncing for your application so ArgoCD detects changes in Git and applies them:
argocd app set nginx-app --sync-policy automated
Benefits of GitOps with ArgoCD
- Auditable Deployments: Every change is tracked in Git.
- Faster Recovery: Rollbacks are as simple as reverting a commit.
- Improved Collaboration: Teams can manage changes via pull requests.
- Simplified Multi-Cluster Management: Manage all clusters centrally.
T
Activity for Today
- Install ArgoCD in your Kubernetes cluster.
- Deploy a sample application using GitOps principles.
- Experiment with enabling auto-sync and making changes to your application in Git to see ArgoCD automatically reconcile the state.
What’s Next?
Tomorrow, we’ll dive deeper into advanced GitOps workflows with Argo Rollouts, exploring canary and blue-green deployments.
Get ready to level up your platform engineering skills! 🚀
👉 Check it out here: Zero to Platform Engineer Repository
Feel free to clone the repo, experiment with the code, and even contribute if you’d like! 🚀
Follow the Series!
🎉 Don’t miss a single step in your journey to becoming a Platform Engineer! 🎉
This post is just the beginning. Here’s what we’ve covered so far and what’s coming up next:
-
Day 2: Day 2: Containers and Docker - The Building Blocks of Cloud Native
-
Day 3: Containers and Kubernetes - The Building Blocks of Cloud Native
-
Day 4: Deployments and Scaling in Kubernetes - Let’s Get Practical
-
Day 6: ConfigMaps and Secrets – Managing Configurations in Kubernetes
👉 Bookmark this blog and check back every day for new posts in the series. 📣 Share your progress on social media with the hashtag #ZeroToPlatformEngineer to connect with other readers!