Deploy ArgoCD on Kubernetes and create ArgoCD application

Hello,
today i’ll walk you through by a tutorial i wrote on how to deploy your own ArgoCD on kubernetes and create your first ArgoCD application.

To start using ArgoCD you have to deploy it to your kubernetes cluster, navigate to ArgoCD docs to read more about the installation.

The installation process is pretty straight forward, you deploy a gigantic yaml file with all the necessary components.
deployment source: https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

 

Prerequisites:

          A kubernetes cluster.
          Load Balancer component on kubernetes cluster.

here is a tutorial of how to install kubernetes cluster:    https://eli-bukin.com/projects/singlenode-rke-cluster-installation/
and this is a tutorial of how to install a Load Balancer on kubernetes:  https://eli-bukin.com/projects/deploy-metallb-load-balancer-on-kubernetes/

What is ArgoCD?

Argo CD is a declarative continuous delivery tool for Kubernetes. It can be used as a standalone tool or as a part of your CI/CD workflow to deliver needed resources to your clusters.

In order to manage infrastructure and application configurations aligned with GitOps, your Git repository must be the single source of truth. The desired state of your system should be versioned, expressed declaratively, and pulled automatically. This is where Argo CD comes in. 

Argo CD is implemented as a Kubernetes controller which continuously monitors running applications and compares the current, live state against the desired target state (as specified in the Git repo). A deployed application whose live state deviates from the target state is considered OutOfSync. Argo CD reports & visualizes the differences, while providing facilities to automatically or manually sync the live state back to the desired target state. Any modifications made to the desired target state in the Git repo can be automatically applied and reflected in the specified target environments.

Right, as i said earlier, let’s deploy the yaml file.

Now let’s check the services it created, as you can see all of them are of ‘ClusterIP’ type.

Change the service type of ‘argocd-server’ service to load balancer, and add an a type and IP, you can patch it with the following command or modify the yaml file and add the specs.

kubectl patch service argocd-server -n argocd --patch "$(cat <<EOF
spec:
  externalTrafficPolicy: Local
  loadBalancerIP: 192.168.66.120
  type: LoadBalancer
EOF
)"

After modifying the service you want to get the admin password to log in to the UI, you can retrieve the password with the following command.

k -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d

Now you can browse to LoadBalancer IP and get to the login page.

After login go to ‘User Info’ and set a new password.

Now let’s configure a repository and create an argocd app.

Let’s connect a repo I already have for this tutorial, it contains a very basic NGINX app, the repo is public so no authentication configuration is required.
 Go to settings -> repositories -> and click ‘connect repo’,
select HTTPS connection method,

Connect repo using GIT,
Repository URL,

No username and password required for this example.

Click ‘Connect’ and you will see the connection status.

And the next thing we need to do is to create an application, you can create your own but I already have something ready.

Go to applications -> new app

Name: nginx-app
project: default
Sync policy: manual
Check ‘AUTO-CREATE-NAMESPACE’, as we are deploying to ‘ aaa-sandbox-02’ namespace which is not yet created.
Repository URL: https://github.com/EliBukin/nginx-for-argocd-poc.git (this is my demo repo)
Path: nginx-server
Cluster URL: https://kubernetes.default.svc
Namespace: aaa-sandbox-02

And hit the ‘Create’ button.

The app is instantly created, as you can see it is in a ‘OutOfSync’ state, this is as a result of the sync policy you defined to be manual, as the ArgoCD now sees the manifest files on the GitHub repository but it doesn’t see a corresponding app on the kubernetes cluster.

Now lets click on the ‘sync’ button and manually sync your resources.

It’s alive!

Now lets go to the CLI to run some commands and see what we got.

As you can see the resources were created on kubernetes cluster.

If you get back to the UI and click on the application tile you will be able to see the resources.

And finally let’s try to get to it from a web browser.

Type the IP of the loadbalancer in the browser and you should get your NGINX.

Looks good, now you are at a point where ArgoCD monitors your GitHub repository for changes, as soon as argo notices that the desired state (the GitHub repo) and the current state (the actual deployment configuration) does not match it will change the deployment status on argo to ‘OutOfSync’.

Lets manualy change the pod count on the ‘deployment.yaml’ file and redeploy…

As you can see now there are two nginx pods and the argo app out of sync.

Now lets click the ‘sync’ button to sync it back to desired state (as it is on GitHub repository).

Well that’s it… this was an example of the process done from the GUI which is very intuitive and convenient, in most cases you will use GUI to interact with ArgoCD, but there will be scenarios when you will need to use it with a CLI.

let’s try that from the CLI as well… follow the link to a walkthrough of how to install CLI and deploy an application.