Cyberithub

How to Install and Use Argo CD - Declarative GitOps CD for Kubernetes

Advertisements

In this article, I will take you through the steps to install and use Argo CD - Declarative GitOps CD for Kubernetes. If you are looking to continuously deploy your application in a Kubernetes Cluster and automate its lifecycle management then Argo CD is one of the best GitOps continuous delivery tool you can use. Argo CD is a declarative, GitOps continuous delivery tool implemented as a Kubernetes controller which continuously monitors the running application and compare its state with the target state. We will understand more about this with the help of an example application deployment in below section.

Important Features

  • It provides automated deployment of applications to specified target environments
  • It has the support for multiple config management/templating tools like Kustomize, Helm, Ksonnet, Jsonnet, plain-YAML etc.
  • It has the ability to manage and deploy to multiple clusters
  • SSO Integration (OIDC, OAuth2, LDAP, SAML 2.0, GitHub, GitLab, Microsoft, LinkedIn)
  • It supports multi-tenancy and RBAC policies for authorization
  • Rollback/Roll-anywhere to any application configuration committed in Git repository
  • It can provide the health status analysis of application resources
  • It has the feature of automated configuration drift detection and visualization
  • It provides the feature of automated or manual syncing of applications to its desired state
  • One of its main feature is the web UI which provides real-time view of application activity
  • One can also use CLI for automation and CI integration
  • Webhook integration (GitHub, BitBucket, GitLab) is fully supported
  • Access tokens for automation can be used with this tool
  • PreSync, Sync, PostSync hooks to support complex application rollouts (e.g.blue/green & canary upgrades)
  • It supports audit trails for application events and API calls

How to Install and Use Argo CD - Declarative GitOps CD for Kubernetes

How to Install and Use Argo CD - Declarative GitOps CD for Kubernetes

Also Read: How to Create and Use a Kubernetes Persistent Volume

Step 1: Prerequisites

a) You should have a Kubernetes Cluster running with atleast one control node and one worker node.

b) You should have kubectl command line tool installed.

c) You should have a valid kubeconfig file.

d) You should have sudo or root access to run privileged commands.

 

Step 2: Create a Namespace

First we need to create a namespace where we will install argo CD and then deploy our apps. Here we are creating a namespace called argocd using kubectl create namespace argocd command as shown below.

root@cyberithub:~# kubectl create namespace argocd 
namespace/argocd created

 

Step 3: Install Argo CD

In the next step we need to install Argo CD using below kubectl apply command.

root@cyberithub:~# kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
customresourcedefinition.apiextensions.k8s.io/applications.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/applicationsets.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/appprojects.argoproj.io created
serviceaccount/argocd-application-controller created
serviceaccount/argocd-applicationset-controller created
serviceaccount/argocd-dex-server created
serviceaccount/argocd-notifications-controller created
serviceaccount/argocd-redis created
serviceaccount/argocd-server created
role.rbac.authorization.k8s.io/argocd-application-controller created
role.rbac.authorization.k8s.io/argocd-applicationset-controller created
role.rbac.authorization.k8s.io/argocd-dex-server created
role.rbac.authorization.k8s.io/argocd-notifications-controller created
role.rbac.authorization.k8s.io/argocd-server created
clusterrole.rbac.authorization.k8s.io/argocd-application-controller created
clusterrole.rbac.authorization.k8s.io/argocd-server created
rolebinding.rbac.authorization.k8s.io/argocd-application-controller created
rolebinding.rbac.authorization.k8s.io/argocd-applicationset-controller created
rolebinding.rbac.authorization.k8s.io/argocd-dex-server created
..........................

 

Step 4: Change argocd-server Service Type to LoadBalancer

By default, Argo CD API Server is not exposed with an external IP so to access the Server you need to expose it by either using LoadBalancer, Ingress or Port Forwarding method. For the demo purpose we are going to use LoadBalancer method. To expose Argo CD API Server with an external IP, you need to change the argocd-server service type to LoadBalancer using below kubectl patch command.

root@cyberithub:~# kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
service/argocd-server patched

 

Step 5: Install argocd Utility

The next step is to install the argocd utility if it is not already installed in your System. You can download the binary under /usr/local/bin directory and provide the execute permission using below commands.

root@cyberithub:~# curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
root@cyberithub:~# chmod +x /usr/local/bin/argocd

 

Step 6: Login to Argo CD Server

To login to Argo CD Server, we are going to use default admin user account. You can get the secrets from the password field of argocd-initial-admin-secret and then store that secret in a variable called argoPass as shown below. Finally pass this variable as an argument to argocd login command for authentication.

root@cyberithub:~# argoPass=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)
root@cyberithub:~# argocd login --insecure --grpc-web k3s_master:32761 --username admin --password $argoPass

 

Step 7: Register a Cluster (Optional)

This step is only required when you are deploying application to an external cluster. But if you are deploying to an internal cluster then you need to use https://kubernetes.default.svc as the application's K8s API server address. To register a cluster, first list all the cluster context using kubectl config get-contexts -o name command as shown below.

root@cyberithub:~# kubectl config get-contexts -o name

Then choose a context name from the above command output and pass it to argocd cluster add command. For example, if you are choosing a context called docker-desktop then you need to run argocd cluster add docker-desktop command as shown below.

root@cyberithub:~# argocd cluster add docker-desktop

The above command will install a ServiceAccount (argocd-manager), into the kube-system namespace of that kubectl context, and binds the service account to an admin-level ClusterRole. Argo CD uses this service account token to perform its management tasks (i.e. deploy/monitoring). More on Argo CD docs.

 

Step 8: Create an Application from a Git Repository

There are two ways to create application. It can be either through CLI or by UI. For the moment we are going to use CLI mode to create our apps. You can choose to use UI mode as well. For the demo purpose, we are going to use a guestbook application available on GitHub repo. To create guestbook application, you need to run below command.

root@cyberithub:~# argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

 

Step 9: Sync the Application

Once the application is created you can view the status by using argocd app get guestbook command as shown below.

root@cyberithub:~# argocd app get guestbook

Initially you will see the status in OutofSync state since the application has yet to be deployed so to sync the application run argocd app sync guestbook command as shown below.

root@cyberithub:~# argocd app sync guestbook

Leave a Comment