Deploying Applications in Kubernetes With Argo CD for Beginners
Deploying applications in Kubernetes can be challenging, especially for beginners. However, tools like Argo CD simplify the process by leveraging GitOps principles to automate and manage deployments seamlessly. In this guide, you’ll learn how to set up and use Argo CD to deploy applications in Kubernetes, step-by-step.
Whether you're new to Kubernetes or looking to streamline your deployment process, this guide is designed to help you get started with Argo CD. Plus, if you need expert assistance, ZippyOPS offers consulting, implementation, and management services for DevOps, DevSecOps, Cloud, AI Ops, Microservices, and more.
What You’ll Learn
Installing and configuring Argo CD.
Deploying applications using GitOps principles.
Monitoring deployments and troubleshooting issues.
Rolling back and managing application versions.
Securing Argo CD for production environments.
Why Use Argo CD?
Argo CD is a declarative, GitOps-powered tool that simplifies Kubernetes application management. Here’s why it’s a game-changer:
Declarative Management: Define your desired cluster state in Git.
Continuous Delivery: Automate deployments with real-time synchronization.
Version Control: Easily roll back to previous versions.
Prerequisites
Before diving in, ensure you have the following:
A Kubernetes cluster (use Minikube, Kind, or managed services like GKE, EKS, or AKS).
kubectl installed and configured to connect to your cluster.
A GitHub or GitLab account to host your Kubernetes manifests.
Basic familiarity with YAML syntax (don’t worry, this guide will help you!).
Step-by-Step Guide to Deploying Applications with Argo CD
1. Setting Up a Kubernetes Cluster
Step 1: Install Minikube
If you don’t have a cluster, use Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube-linux-amd64
sudo mv minikube-linux-amd64 /usr/local/bin/minikube
Step 2: Start Minikube
Run the following command:
minikube start
Step 3: Verify Cluster
Confirm the cluster is running:
kubectl cluster-info
kubectl get nodes
2. Installing Argo CD
Step 1: Create Namespace
Argo CD runs in its own namespace for isolation:
kubectl create namespace argocd
Step 2: Install Argo CD
Apply the official manifests:
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Step 3: Verify Installation
Check the Argo CD pods:
kubectl get pods -n argocd
3. Accessing the Argo CD UI
Step 1: Expose Argo CD
Expose the argocd-server to your local machine:
kubectl port-forward svc/argocd-server -n argocd 8080:443
Step 2: Retrieve Admin Credentials
Fetch the default admin password:
kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d
Step 3: Login to UI
Open https://localhost:8080 in your browser.
-
Log in with:
Username: admin
Password: Retrieved in the previous step.
4. Connecting Argo CD to Your Git Repository
Step 1: Prepare a Git Repository
Create a Git repository (e.g., on GitHub).
Add your Kubernetes manifests. Here’s a sample deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19
ports:
- containerPort: 80
Step 2: Add Repository to Argo CD
From the UI:
Navigate to Settings > Repositories.
Add your Git repository URL and authentication details.
Or, use the CLI:
argocd repo add
5. Deploying Your First Application
Step 1: Create an Application
In the Argo CD UI:
Click New App.
-
Fill in the details:
App Name: nginx-app
Project: default
Repository URL: Your Git repo URL
Path: Path to deployment.yaml
Cluster URL: https://kubernetes.default.svc
Namespace: default
Step 2: Sync the Application
After creating the app:
Click Sync in the Argo CD UI.
Watch as the app deploys to your Kubernetes cluster.
6. Automating Deployments
Step 1: Enable Auto-Sync
Enable continuous synchronization:
argocd app set nginx-app --sync-policy automated
Step 2: Test Changes
Modify the deployment.yaml in Git.
Push changes to the repository.
Argo CD will detect the changes and automatically sync them to the cluster.
7. Monitoring and Troubleshooting
Step 1: Monitor Application Health
In the UI, check:
Health: Indicates if the application is running as expected.
Sync Status: Ensures the cluster state matches Git.
Step 2: View Logs
If something goes wrong:
kubectl logs -n argocd
Step 3: Roll Back Changes
Roll back to a previous state:
argocd app rollback nginx-app
8. Securing Argo CD
Step 1: Change Default Admin Password
Change the default admin password:
argocd account update-password
Step 2: Integrate SSO
For production environments, integrate with Single Sign-On (SSO) solutions like GitHub or LDAP.
GitOps Best Practices
Branch Strategies: Use separate branches for development, staging, and production.
Code Reviews: Enforce peer reviews for manifest changes.
Audit Logs: Regularly review Argo CD logs for compliance and debugging.
Conclusion
Argo CD is a powerful yet beginner-friendly tool for managing Kubernetes deployments using GitOps principles. By following this guide, you’ll be able to deploy, monitor, and manage applications efficiently.
If you’re looking for expert assistance, ZippyOPS provides consulting, implementation, and management services for DevOps, DevSecOps, Cloud, AI Ops, Microservices, and more. Explore their services, products, and solutions. For demo videos, check out their YouTube Playlist.
If this seems interesting, email them at [email protected] for a call.
By mastering Argo CD and GitOps, you’re well on your way to becoming a Kubernetes deployment
Recent Comments
No comments
Leave a Comment
We will be happy to hear what you think about this post