Deploying Applications in Kubernetes with Argo CD for Beginners
Learn how to deploy applications seamlessly in Kubernetes using Argo CD, from installation to securing and automating deployments with GitOps principles.
Join the DZone community and get the full member experience.
Join For FreeDeploying applications in Kubernetes can be complex, especially for newcomers. Enter Argo CD, a GitOps-powered, declarative tool designed to automate Kubernetes application deployments. In this workshop, you’ll learn how to set up and use Argo CD to deploy applications seamlessly, with a step-by-step crafted for complete beginners.
What You’ll Learn
- Installing and configuring Argo CD.
- Deploying applications using GitOps principles.
- Monitoring deployments and troubleshooting.
- Rolling back and managing application versions.
- Securing Argo CD for production use.
Why Argo CD?
Argo CD simplifies application management in Kubernetes by continuously syncing your cluster with manifests defined in Git repositories. Benefits include:
- Declarative Management: Define the desired cluster state in Git.
- Continuous Delivery: Automate deployments with real-time sync.
- Version Control: Roll back to previous versions with ease.
Prerequisites
Before diving in, ensure you have:
- A Kubernetes cluster (use Minikube, Kind, or a managed service like GKE, EKS, 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 (covered in this workshop if you’re new).
Step-by-Step Guide
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 command minikube start
after installing Minikube on your system:
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 to install Argo CD:
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 to the repository. Use this 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 (SSH or HTTPS).
Or, use the CLI:
argocd repo add <REPO_URL> --username <USERNAME> --password <PASSWORD>
5. Deploying Your First Application
Step 1: Create an Application
In the Argo CD UI:
- Click New App.
- Fill in the following:
- 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 <POD_NAME>
Step 3: Roll Back Changes
Roll back to a previous state:
argocd app rollback nginx-app <REVISION>
8. Securing Argo CD
Step 1: Change Default Admin Password
Change the default admin password using the command argocd account update-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 offers a beginner-friendly yet powerful way to manage Kubernetes deployments using GitOps principles. This workshop equips you with the skills to deploy, monitor, and manage applications efficiently. By adhering to these practices, you’re well on your way to mastering Kubernetes continuous delivery.
Opinions expressed by DZone contributors are their own.
Comments