Deploying Applications in Kubernetes with Argo CD for Beginners

Deploying 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:

  1. A Kubernetes cluster (use Minikube, Kind, or a managed service like GKE, EKS, AKS).
  2. kubectl installed and configured to connect to your cluster.
  3. A GitHub or GitLab account to host your Kubernetes manifests.
  4. 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:

Shell

 

Step 2: Start Minikube

Run the command minikube start after installing Minikube on your system:

Shell

 

Step 3: Verify Cluster

Confirm the cluster is running:

Shell

 

2. Installing Argo CD

Step 1: Create Namespace

Argo CD runs in its own namespace for isolation:

Shell

 

Step 2: Install Argo CD

Apply the official manifests to install Argo CD:

Shell

 

Step 3: Verify Installation

Check the Argo CD pods:

Shell

 

3. Accessing the Argo CD UI

Step 1: Expose Argo CD

Expose the argocd-server to your local machine:

Shell

 

Step 2: Retrieve Admin Credentials

Fetch the default admin password:

Shell

 

Step 3: Login to UI

  1. Open https://localhost:8080 in your browser.
  2. 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

  1. Create a Git repository (e.g., on GitHub).
  2. Add your Kubernetes manifests to the repository. Use this sample deployment.yaml:
YAML

 

Step 2: Add Repository to Argo CD

From the UI:

  1. Navigate to Settings > Repositories.
  2. Add your Git repository URL and authentication details (SSH or HTTPS).

Or, use the CLI:

Shell

 

5. Deploying Your First Application

Step 1: Create an Application

In the Argo CD UI:

  1. Click New App.
  2. 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:

  1. Click Sync in the Argo CD UI.
  2. Watch as the app deploys to your Kubernetes cluster.

6. Automating Deployments

Step 1: Enable Auto-Sync

Enable continuous synchronization:

Shell

 

Step 2: Test Changes

  1. Modify the deployment.yaml in Git.
  2. Push changes to the repository.
  3. 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:

Shell

 

Step 3: Roll Back Changes

Roll back to a previous state:

Shell

 

8. Securing Argo CD

Step 1: Change Default Admin Password

Change the default admin password using the command argocd account update-password:

Shell

 

Step 2: Integrate SSO

For production environments, integrate with Single Sign-On (SSO) solutions like GitHub or LDAP.

GitOps Best Practices

  1. Branch Strategies: Use separate branches for development, staging, and production.
  2. Code Reviews: Enforce peer reviews for manifest changes.
  3. 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.

Source:
https://dzone.com/articles/deploying-applications-in-kubernetes-with-argo-cd