DEV Community

Cover image for Beginner's Guide to Argo CD: Streamlining Kubernetes Deployments with GitOps
Abhishek
Abhishek

Posted on • Updated on

Beginner's Guide to Argo CD: Streamlining Kubernetes Deployments with GitOps

The Traditional CI/CD Pipeline

Before Argo CD, deploying applications in Kubernetes usually followed a traditional CI/CD pipeline approach.

Developers pushed code changes to Git, triggering automated tests for quality assurance. Upon successful testing, code was built into Docker images and stored in a registry. These images were then linked to deployment manifests, which were manually updated and applied to the Kubernetes cluster using kubectl.
Image description
Let's break it down. Imagine you've developed an application and need it to run on a cluster with specific configurations, such as Pods and Services with external IPs. This setup represents the desired state of your application.

Now, traditionally, whenever there's a change in your application's repository or if the desired state isn't met in the cluster, manual intervention was required. This involved checking the cluster and making adjustments to ensure it matched the desired state, which could lead to mistakes and errors.

With Argo CD, it's designed to simplify application deployment with its features, streamlining the entire process using GitOps principles. With Git as the source of truth for both your application, you can also keep track of the health and sync status of application deployment and get notifications for any changes. If anything goes wrong with new updates, you can easily undo changes with the rollback feature.

Introduction to Argo CD:

  • Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.
  • It's designed to simplify and automate the deployment and management of applications, ensuring continuous synchronization with the latest code changes.
  • Argo CD is built with the GitOps model at its core, where the repository becomes the primary source of truth for your application's state. your repository stores essential components needed for your application, such as Kubernetes manifests, Kustomize templates, Helm charts, and configuration files. The components stored in the repository act as a roadmap, showing the steps needed to deploy your app successfully. Image description

How Argo CD Works

  • Argo CD operates on a GitOps-based continuous delivery (CD) model with a pull-based design.
  • Argo CD operates with two repositories: one for your application and another for defining the desired state of the cluster. It's like having a blueprint for how your cluster should be configured.
  • When Argo CD notices any differences between the current state of your cluster and the defined blueprint (Git manifest), it works to make them match.
  • If everything matches the blueprint, it shows "Synced." If not, it shows "OutOfSync," indicating there are differences to resolve.

Image description

Prerequisites

  • Basic understanding of managing a Kubernetes cluster, including concepts like pods, services, and namespaces.
  • Familiarize with YAML, as Argo CD configuration files and Kubernetes manifests are commonly expressed in YAML format.
  • You need a running kubernetes cluster.
  • Installed kubectl command-line tool.

Install Argo in Your Cluster

Begin by creating a dedicated namespace for Argo CDusing the following command:

PS C:\Users\hp> kubectl create namespace argocd
Enter fullscreen mode Exit fullscreen mode

Next, apply Argo CD YAML manifest to your cluster using kubectl. This will install the Argo CD API, controller, and Custom Resource Definitions (CRDs):

PS C:\Users\hp> kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Enter fullscreen mode Exit fullscreen mode

Monitor the deployment progress by checking the status of Argo components:

PS C:\Users\hp> kubectl get deployments -n argocd
NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
argocd-applicationset-controller   1/1     1            1           26h
argocd-dex-server                  1/1     1            1           26h
argocd-notifications-controller    1/1     1            1           26h
argocd-redis                       1/1     1            1           26h
argocd-repo-server                 1/1     1            1           26h
argocd-server                      0/1     1            0           26h
guestbook-ui                       1/1     1            1           25h
Enter fullscreen mode Exit fullscreen mode

Connecting to Argo:

Argo CD does not automatically expose its API server externally. You can connect to it using one of the following methods:

  1. Service Type: LoadBalancer If you prefer to use a LoadBalancer, you can change the service type of the argocd-server to LoadBalancer.

  2. Ingress
    If you have an ingress controller set up, you can configure an ingress resource to direct traffic to the argocd-server service.

  3. Port Forwarding Use port forwarding to access Argo CD locally on your machine:

To access Argo CD locally on your machine, you can use port forwarding. Run the following command in your terminal:

PS C:\Users\hp> kubectl port-forward svc/argocd-server -n argocd 8080:443
Enter fullscreen mode Exit fullscreen mode

This command redirects your local port 8080 to port 443 of Argo CD service. Now you can access your ArgoCD dashboard at 127.0.0.1:8080.

Image description

Obtaining the Initial Password:

Before you can login, you need to retrieve the initial password for the default admin user. This is generated automatically during Argo’s installation process.
You can access it by running the following argocd command:

PS C:\Users\hp> argocd admin initial-password -n argocd
V0l6LBKZXESYk6Gh
Enter fullscreen mode Exit fullscreen mode

Use these credentials to login to Argo.

To interact with Argo CD from the command line interface (CLI), you'll need to install the Argo CD CLI tool. Refer to the official documentation for detailed instructions on installing the CLI: ArgoCD CLI Installation.

Login to Argo CD CLI: Use the initial password obtained earlier to log in to Argo CD.

PS C:\Users\hp> argocd login localhost:8080
Enter fullscreen mode Exit fullscreen mode

Once logged in, you can update the password using the following command:

PS C:\Users\hp> argocd account update-password
Enter fullscreen mode Exit fullscreen mode

Practical Example: Deploying an Application with Argo CD

Create Application using CLI

Step 1: Create Kubernetes Manifest for Application

Begin by creating a Kubernetes manifest for your application. For this demonstration, we'll utilize the guestbook example from the Argo CD official example apps repository available at https://github.com/argoproj/argocd-example-apps.

Step 2: Create Argo CD Application Manifest

Before deploying your application with Argo CD, you need to create an application.yaml configuration file. This file contains essential settings such as the repository URL, path to manifests, namespace, and other configurations.
Next, create an Argo CD Application manifest for the guestbook example:

guestbook-app.yaml:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: guestbook
spec:
  destination:
    server: 'https://kubernetes.default.svc'
    namespace: default
  source:
    repoURL: 'https://github.com/argoproj/argocd-example-apps'
    path: guestbook
    targetRevision: HEAD
  project: default
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
Enter fullscreen mode Exit fullscreen mode

Step 3: Apply Argo CD Application Manifest

Apply the Argo CD Application manifest using the following command:

PS C:\Users\hp> kubectl apply -f guestbook-app.yaml
Enter fullscreen mode Exit fullscreen mode

After deploying the application, review its status and configuration details in the Argo CD dashboard.

Image description

Create Application using UI

Step 1: Log into Argo CD

Use the admin user and its password, log into Argo CD
Image description

Step 2: Create Application

Let's create an Argo CD application using the guestbook example from the Argo CD official example apps repository.
https://github.com/argoproj/argocd-example-apps
Click the “+ New App” button

Image description

Enter the following information:

Image description

Git Repo (Source/desired state):

Image description

Destination:

Image description

Then click “CREATE” button at the top.

Image description

Wait for a few minutes until the app “guestbook” is deployed successfully.

Image description

After deployment, verify that the service is running by executing:

PS C:\Users\hp> kubectl get svc -n argocd
Enter fullscreen mode Exit fullscreen mode

Additionally, you can access the guestbook app through port forwarding:

PS C:\Users\hp> kubectl port-forward svc/guestbook-ui -n argocd 8081:80
Enter fullscreen mode Exit fullscreen mode

Access it from a web browser on http://localhost:8081

Image description
Or verify using the Argo CD command-line tool:

PS C:\Users\hp> argocd app get guestbook
Name:               argocd/guestbook
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          argocd
URL:                https://localhost:8080/applications/guestbook
Repo:               https://github.com/argoproj/argocd-example-apps.git
Target:             HEAD
Path:               guestbook
SyncWindow:         Sync Allowed
Sync Policy:        Automated
Sync Status:        Synced to HEAD (d7927a2)
Health Status:      Healthy

GROUP  KIND        NAMESPACE  NAME          STATUS  HEALTH   HOOK  MESSAGE
       Service     argocd     guestbook-ui  Synced  Healthy        service/guestbook-ui created
apps   Deployment  argocd     guestbook-ui  Synced  Healthy        deployment.apps/guestbook-ui created
Enter fullscreen mode Exit fullscreen mode

After defining your application in the Argo CD Application Manifest, any updates or changes to your Kubernetes manifests, such as deployments or services, can be made directly in your code. Once you've made your changes, simply push the updated files to your synced GitHub repository. Argo CD will automatically detect these changes and handle the deployment process, ensuring that your application stays up to date with the latest configurations.

Wrap-Up

With this guide, we've explored the basics of Argo CD. There is an advanced features to explore within Argo CD. Advanced features like integration notifications, ApplicationSets, RBAC, and more.
For more information refer the official - Argo CD Documentation

Additional Resources:
Argo CD: The De Facto Continuous Delivery Tool for Kubernetes

Top comments (1)

Collapse
 
bcouetil profile image
Benoit COUETIL 💫

Welcome here, and thank you for sharing !

With Argo CD, it's designed to simplify application deployment with its features, streamlining the entire process using GitOps principles.

Which part exactly is streamlined ? Does it do every steps in the pipeline showed before ?

And what would you tell someone that has a traditional pipeline, to convince him to migrate to ArgoCD ?