Install Argocd CLI add a repo and deploy an application
Hello, in the previous tutorial i have demonstrated how to install argocd on a kubernetes cluster and use GUI to add a GitHub repository and create argo app.
today I will guide you through a tutorial on how to install the ARGOCD CLI and work with it to achieve practically the same goals… add a repository, and then create an application in Argo that will install and synchronize our application from the Git repository
Prerequisites:
A kubernetes cluster with ArgoCD deployed on it.
KUBECTL configured.
GitHub repository containing an application to deploy and sync.
What is ArgoCD CLI, and what is it good for?
ArgoCD CLI is the command-line interface for Argo CD, which is a declarative, GitOps continuous delivery tool for Kubernetes. The CLI allows you to interact with the Argo CD server using terminal commands, making it easier to manage the lifecycle of applications and their configurations within Kubernetes environments.
It’s particularly useful for:
Automating deployments to Kubernetes by syncing with a Git repository.
Managing application configurations in a declarative way.
Monitoring the state of applications and ensuring they match the desired state in the Git repository.
Rolling back to previous versions if necessary.
The CLI is part of the broader Argo CD ecosystem, which aims to simplify the process of continuous delivery for Kubernetes, aligning with the principles of GitOps. This means that any changes to applications or configurations are made through changes in source control, which then get automatically applied to the live system.
To install ArgoCD CLI you have to download the binary, and install it in your path.
navigate to it’s GitHub releases page select the one you need, and modify the curl command with your value.
curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/download/v2.11.0/argocd-linux-amd64 && \
chmod +x argocd && \
sudo install -m 555 argocd /usr/local/bin/argocd
Let’s list the clusters.
argocd cluster list
That did not work… You first have to login to the cluster.
To do that you will need the ArgoCD server service external IP, you can get it by querying the kubernetes API.
get the external IP of the ‘argocd-server’, and use it to login.
k get svc -n argocd
Now log in to ArgoCD from CLI with the following command, use the same username and password as in the GUI login.
you will get a warning as a result of using a self signed certificate, if you don’t want to get the warning you can use ‘–insecure’ flag on the login command.
you can specify the username and password with flags ‘–username –password’ if you wish.
argocd login 192.168.66.120
From this stage you are logged in and can list some resources, you can list apps and repos and much more, as you can see the resources from the previous tutorial are listed.
Now let’s add a new github repository and create an application from it.
To add a new repository you can use the following command.
in this tutorial i am pointing to something I have already prepared, it’s a repository containing a FLASK MORSE app, I am using it primarily for these kind of purposes, its a simplest app translates URL inputs to morse code, you can take whatever repo you like .
GitHub repo: https://github.com/EliBukin/helm-flask-morse-app
Docker Image: https://hub.docker.com/repository/docker/elibukin/flask-morse-app/general
argocd repo add https://github.com/EliBukin/helm-flask-morse-app.git
Now that the repo is added let’s create the Argo application, you can use the following command.
argocd app create helm-flask-morse-app \
--repo https://github.com/EliBukin/helm-flask-morse-app.git \
--path . \
--dest-server https://kubernetes.default.svc \
--helm-set service.type=LoadBalancer \
--helm-set service.port=80 \
--dest-namespace flask-morse-app \
--sync-policy manual \
--project default
Let’s break down the argocd app create
command and its options:
argocd
:
This is the command-line interface (CLI) tool for interacting with Argo CD.app create
:
This subcommand is used to create a new application in Argo CD.helm-flask-morse-app
:
This is the name you’re giving to the application within Argo CD. It’s a unique identifier for this application.--repo https://github.com/EliBukin/helm-flask-morse-app.git
:
This specifies the Git repository URL where the application manifests are stored.--path .
:
This option specifies the path within the Git repository where the application manifests are located. In this case, it’s set to “.” which typically means the root directory of the repository.--dest-server https://kubernetes.default.svc
:
This option specifies the Kubernetes API server where the application will be deployed. In this case, it’s set to the default Kubernetes service in the cluster.--helm-set service.type=LoadBalancer
:
This option sets a Helm value for theservice.type
parameter. It configures the type of Kubernetes service that will be created for the application. Here, it’s set toLoadBalancer
, which typically exposes the service externally using a cloud provider’s load balancer.--helm-set service.port=80
:
This option sets a Helm value for theservice.port
parameter. It specifies the port number on which the service will listen for incoming traffic.--dest-namespace flask-morse-app
:
This option specifies the namespace in which the application will be deployed in the Kubernetes cluster. Here, it’s set toflask-morse-app
.--sync-policy manual
:
This option specifies the synchronization policy for the application. In this case, it’s set tomanual
, meaning that synchronization of the application’s desired state with the actual state in the cluster must be triggered manually.--project default
:
This option specifies the project within Argo CD where the application will be created. In this case, it’s set to the default project.
Now if you run ‘argocd app list’ you will see the new application created, it is in ‘OutOfSync’ status, and it’s because the manual sync policy you specified when running the app create command.
Let’s sync the app…
argocd app sync helm-flask-morse-app
OOOPS… not so fast, as you can see the error says that there is no ‘flask-morse-app’, you got to manually create the ‘flask-morse-app’ namespace as ArgoCD CLI does not provide that functionality yet…
k create ns flask-morse-app
It’s all good now, synced successfully.
Good! It is now successfully synced, lets go to app URL at: http://192.168.66.129/morse/<put some caption to translate>
Well that concludes our activity here today :> we installed ArgoCD CLI, added a GitHub repository, created Argo App and synced it with the source of truth.