# ArgoCD For Beginners ⎈

Hey Everyone, welcome to the new blog. In today's blog we are going to learn about **ArgoCD**. So without wasting time let's get started.

# **What is ArgoCD?**

ArgoCD is referred to as a declarative **GitOps tool** that is **Kubernetes-based**. Let's attempt to break this down. **"GitOps"** is a pattern where you take the code you have written and pushed to the **Git registry** (eg: GitHub, GitLab, Bitbucket) and bring it to the deployment and this is primarily done and executed as **automation**. The term **"declarative"** implies that the deployment has precisely the **same architecture** which you need and have chosen. So if ever there is a situation where something gets altered in the deployment then it will **move back to the former state** (the one which you have specified).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742379169072/ab1c0e46-7493-4b7c-b565-75d3b4274be2.png align="center")

# **CD workflow without ArgoCD**

So whenever the code changes are **pushed** to the **git repository**, they follow some **series of steps** that take them through to the **deployment**. These processes are automated and referred to as **CI/CD pipeline**. So after the code changes are **pushed**, they get **tested**, an **image is created**, pushed on the **DockerHub** or other registry, **Manifest files** are refreshed and lastly using **kubectl apply**. it is applied to the **Kubernetes cluster**.

But in this case, we have to face and resolve challenges like

* Install and setup tools like kubectl
    
* Configuring access to Kubernetes
    
* Configuring access to cloud providers
    
* Several security challenges
    
* No visibility of deployment status
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742378934131/553daaaa-e4fb-4721-a432-e240fe25b9f4.png align="center")

# **CD workflow with ArgoCD**

So in a typical scenario the workflow described above is applied, but while **using Kubernetes** we may be required to modify this **workflow**. It is critical to understand that based on the established best practice of the **Git repository**, we must have two isolated repositories for **Code files** and **application configuration** (k8s manifests).

The primary benefit is there can be a point where we want to update only the **config files** but do not wish the test -&gt; to build etc process to execute since the configs can be updated separately from the application compiled. Having this as a reference now **ArgoCD** (which is deployed on your Kubernetes Cluster) maintains the state you described in the **configuration repositories**.

So if were to use the earlier **CI/CD pipeline** then it would have been too difficult to manage and configure. Once the application is created and up the changes are reflected in the **configuration files**. These changes are detected by **ArgoCD** and pulled into the **cluster**.

**\*\*\*ArgoCD works on the pull method and not like the usual push method.**\*\*\*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742378973618/bab72141-f1b5-47c7-8b07-f33db1db6856.png align="center")

# **Advantages of using ArgoCD**

* **Git as a single source of truth:**
    
    That implies that if changes are to happen in the **Kubernetes cluster** then the **git repository** is a location where one can check and verify whether everything is proceeding as stated in the manifests and any instance which is out of instructions is being rolled back.
    
* **Easy Rollback:**
    
    This is a very necessary feature of ArgoCD as it allows us to go back to the **former state** if something was **wrong or misconfigured** with the **cluster.**
    
* **Cluster Disaster Recovery (CDR):**
    
    So if one of my servers fails then I can **deploy another cluster** with ArgoCD and reference it to the same repository then **recovery process** becomes really **more efficient** and quick.
    
* **Kubernetes Access Control:**
    
    We can control the access to the **cluster** directly using **git** so that we do not have to deal with granting the **cluster access** to an **external tool**.
    

# Lets Experiment with it**..**

ArgoCD is very simple to install and set up. We are going to see it from an example perspective.

1. Install ArgoCD into your cluster using the following commands.
    
    ```bash
    kubectl create namespace argocd
    ```
    
    ```bash
    kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
    ```
    
2. Now that we have installed the argocd in the argocd namespace we can now create a yaml file with the following code. I will name the YAML file as `application.yaml`.
    
    ```yaml
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: wmd-argo-application
      namespace: argocd
    spec:
      project: default
    
      source:
        #Your repo link here
        repoURL: https://github.com/argoproj/argocd-example-apps.git
        targetRevision: HEAD
        #Location where the manifests are stored
        path: ArgoCD/dev
      destination: 
        server: https://kubernetes.default.svc
        namespace: wmd
    
      syncPolicy:
        syncOptions:
        - CreateNamespace=true
    
        automated:
          selfHeal: true
          prune: true
    ```
    
3. Create a `dev` folder and place your deployment and service files into it.
    
4. Create a namespace for our application.
    
    ```bash
    # You can give any name to your namespace and update respective files
    kubectl create namespace wmd
    ```
    
5. Now we have to apply the `application.yaml` file to the cluster. We can do that using the `kubectl apply` command like below.
    
    ```bash
    kubectl apply -f application.yaml
    ```
    
6. Let's go and check out it on the ArgoCD dashboard. To see the dashboard run the following command on your terminal.
    
    ```bash
    kubectl port-forward svc/argocd-server 8080:443 -n argocd
    ```
    
    and now you can go to [`http://localhost:8080`](http://localhost:8080) to access the ArgoCD dashboard.
    
7. In the `Username` field enter `admin` and to generate a password run the following commands into the terminal.
    
    ```bash
    kubectl get secret argocd-initial-admin-secret -n argocd -o yaml
    ```
    
    and you will get output something like
    
    ```yaml
    apiVersion: v1
    data:
      password: VktPYkNUZGZRcjNVk1ibQ==
    kind: Secret
    metadata:
      creationTimestamp: "2023-02-14T14:27:52Z"
      name: argocd-initial-admin-secret
      namespace: argocd
      resourceVersion: "1126"
      uid: c830da0d-8ff2-4719-8c5d-6cde9faf44e8
    type: Opaque
    ```
    
    We are not done yet, copy the password in this case mine will be `VktPYkNUZGZRcjlNVk1ibQ==` now put this password into another command to decode it and obtain the real password. Run the following command to decode it.
    
    ```bash
    # Change after echo with your password
    echo VktPYkNUZGZRcjlNVk1ibQ== | base64 --decode
    ```
    
    Now copy the password that is obtained (Remember to omit `%` at the end of the password obtained) and put it into the ArgoCD dashboard.
    
8. Now you will be able to view the application in the dashboard.
    
9. Click on the application name and you are able to see a beautiful map of your deployment.
    

You could find all the possible information regarding the cluster here such as the pod, cluster, and service health. ArgoCD fetches the changes every **3 minutes** this could be altered using webhooks and other approaches.

And it's done you have successfully installed and used ArgoCD to your cluster now whenever you need to make any changes in the deployment then directly you can modify the manifest and push the code to git repository and changes will be reflected in ArgoCD automatically.

# **Resources**

* [ArgoCD Tutorial for Beginners](https://youtu.be/MeU5_k9ssrs?si=4dvRj3fnbuWV70zF)
    
* [ArgoCD Tutorial for beginners-02](https://youtu.be/igg8hIVD24c?si=3mbHD30QEHlnuidm)
    
* [Argo CD - Read the Docs](https://argo-cd.readthedocs.io/en/stable/)
    

# **Thank you so much for reading 💙**

**Like | Follow | Subscribe to the Newsletter.**

**Catch me on my socials here:** [**https://bio.link/yashpawar**](https://bio.link/yashpawar)
