ArgoCD: Learn how to set up and use ArgoCD
Introduction
Hello, fellow software engineers and tech enthusiasts! If you're in the world of DevOps or cloud-native applications, you've probably heard the buzz around GitOps. GitOps is revolutionizing the way we manage applications and infrastructure. At the heart of this practice is ArgoCD—an open-source, declarative, GitOps continuous delivery tool for Kubernetes.
In this guide, we’ll explore how to get started with ArgoCD, step by step. Whether you're new to GitOps or familiar with Kubernetes, this guide will help you set up ArgoCD in your environment, deploy applications, and take advantage of its powerful features. Let's dive into the world of automation, declarative deployments, and continuous delivery!
1. What is ArgoCD?
Before jumping into the setup, let’s start with understanding what ArgoCD is and why it’s gaining so much popularity.
ArgoCD Overview:
ArgoCD is a Kubernetes-native tool for managing and syncing your application deployments through a GitOps approach. In a traditional CI/CD setup, application state is managed through pipelines. In contrast, ArgoCD continuously monitors your Git repository and ensures that the actual state of your Kubernetes cluster matches the desired state defined in your Git repository. This enables continuous synchronization and recovery from configuration drift.
Declarative: ArgoCD works with the declarative configuration stored in Git.
Self-healing: If the actual state drifts from the desired state, ArgoCD will automatically bring it back in line.
Real-time visualization: You get a real-time view of your applications and clusters.
Suggested Image: A flow diagram showing how ArgoCD monitors a Git repository and continuously syncs with the Kubernetes cluster. Include components like Git (with application manifests) → ArgoCD → Kubernetes Cluster.
2. Setting Up ArgoCD
Now that we know what ArgoCD is, let’s dive into the practical steps to set it up on your Kubernetes cluster.
Step 1: Install ArgoCD on Kubernetes
First, we need to install ArgoCD in our Kubernetes cluster. The installation process is straightforward, as ArgoCD comes with Kubernetes manifests that you can easily apply to your cluster.
Create a namespace for ArgoCD:
shCopy codekubectl create namespace argocd
Install ArgoCD components: You can install ArgoCD using the following command:
shCopy codekubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
This command installs all the necessary ArgoCD components, such as the API server, controller, repo-server, and Redis.
Verify the installation: Once installed, check if all ArgoCD components are running:
shCopy codekubectl get pods -n argocd
You should see the ArgoCD pods in a "Running" state.
Suggested Image: A diagram showing the architecture of ArgoCD within a Kubernetes cluster, with components like the API server, controller, and Redis.
Step 2: Accessing the ArgoCD Dashboard
After ArgoCD is installed, you’ll want to access the web dashboard to manage your applications visually.
Expose the ArgoCD server: By default, the ArgoCD API server is not exposed outside the cluster. You can expose it using a
kubectl port-forward
command:shCopy codekubectl port-forward svc/argocd-server -n argocd 8080:443
Login to the dashboard: Open your browser and navigate to
https://localhost:8080
. You’ll be prompted for login credentials. The default username isadmin
, and you can retrieve the password using the following command:shCopy codekubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d
Change the default password: For security reasons, you should change the default password after logging in.
Suggested Image: Screenshot of the ArgoCD web dashboard with descriptions of key sections, such as "Applications," "Projects," and "Settings."
3. Deploying Your First Application with ArgoCD
Now that ArgoCD is installed, let's deploy an application. We’ll use a sample application stored in a Git repository. ArgoCD will sync the Kubernetes manifests in the repo with the Kubernetes cluster.
Step 1: Add a Git Repository
Add the repository to ArgoCD: In the ArgoCD dashboard, go to "Repositories" and click on "Connect Repo using HTTPS/SSH." Enter the details of your Git repository that contains the Kubernetes manifests for your application.
Specify the application path: If your repository has multiple applications, specify the correct folder path where the Kubernetes manifests are located.
Suggested Image: A diagram showing the connection between the Git repository and the ArgoCD dashboard, highlighting how changes in Git are automatically synced to the Kubernetes cluster.
Step 2: Create an Application in ArgoCD
Define the application: In the ArgoCD dashboard, go to the "Applications" section and click "New App." Provide the application name, project, and the target cluster (which is often the same cluster where ArgoCD is installed).
Specify the sync policy: You can set the sync policy to automatic, where ArgoCD will automatically apply changes from the Git repository to the cluster. Alternatively, you can choose manual sync and trigger updates yourself.
Deploy the application: Once everything is configured, click "Create" and ArgoCD will start syncing the application to your Kubernetes cluster.
Suggested Image: Flowchart showing the process of defining an application in ArgoCD, syncing it with the Kubernetes cluster, and automatically applying updates from the Git repository.
4. Advanced Features of ArgoCD
Step 1: Self-Healing and Syncing
One of the most powerful features of ArgoCD is its ability to detect drift between the desired state (in Git) and the actual state (in Kubernetes). If any manual changes are made directly to the cluster, ArgoCD will automatically revert them.
Enable Auto-Sync: This feature ensures that any changes to your Git repository are immediately reflected in the Kubernetes cluster.
Sync Status: The ArgoCD dashboard provides a clear view of whether your application is "Synced" or "OutOfSync." If it’s "OutOfSync," ArgoCD will trigger the necessary changes to restore the desired state.
Suggested Image: A visual representation showing how ArgoCD monitors for drift between the Git repository and Kubernetes cluster, with arrows indicating the syncing process.
Step 2: Rollbacks and History
ArgoCD keeps track of the entire history of deployments, allowing you to roll back to any previous state if needed. This feature is especially useful when something goes wrong with a new deployment.
View History: In the ArgoCD dashboard, navigate to the "History" section of an application. Here, you can see all the previous revisions and select one to roll back.
Perform Rollback: Simply click on a previous revision and hit "Rollback" to revert the cluster to the desired state.
Suggested Image: A timeline diagram showing different deployment revisions in ArgoCD, with the ability to roll back to any previous state.
5. Working with Notifications and Alerts
ArgoCD can integrate with various tools to send notifications or alerts based on deployment statuses. This ensures that you are always aware of what's happening in your environment.
Step 1: Set up Notifications
Integration with Slack, Webhooks, and Email: ArgoCD can notify you via Slack, email, or custom webhooks whenever a sync fails or succeeds.
Configure Notifications: In the ArgoCD settings, navigate to "Notifications" and set up your preferred integration method (e.g., Slack webhook URL or email address).
Suggested Image: A flow diagram showing ArgoCD sending notifications to various channels such as Slack, email, or other monitoring tools.
Conclusion
ArgoCD is a powerful tool for managing your Kubernetes applications through GitOps, offering declarative, self-healing deployments with real-time visualization. Whether you’re deploying small applications or managing large-scale microservices, ArgoCD simplifies continuous delivery for Kubernetes environments. By following this guide, you now have the knowledge to install ArgoCD, deploy applications, and take advantage of its advanced features.
Have any questions or experiences with ArgoCD? Leave a comment below, and let’s discuss!
Meta Description: Learn how to set up and use ArgoCD, a GitOps continuous delivery tool for Kubernetes, with this comprehensive step-by-step guide. Perfect for software engineers and DevOps enthusiasts.
Slug: how-to-use-argocd
Subscribe to my newsletter
Read articles from Deepak parashar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by