This blog will show different ways of creating applications in ArgoCD, So Stay Tuned!
PREREQUISITES
- Kubernetes Cluster up and running on Local, minikube, or any Cloud providers
- GitHub or Gitlab Account
First, let us understand few concepts of ArgoCD
ArgoCD is a GitOps continuous delivery tool that means you define all your applications, manifests, and resources that you want to deploy in your Kubernetes cluster, you define all of them in your GitHub repository, and then the ArgoCD will pull the changes from your GitHub repository and deploy resources for you in your Kubernetes cluster.
It supports:-
- Kubernetes YAML files
- Helm Charts
- Kustomize files
- Template files that generate Kubernetes manifest.
Continuous Delivery workflow with ArgoCD
- Firstly, deploy ArgoCD in Kubernetes Cluster.
- Secondly, configure ArgoCD and tell it to connect to the particular GitHub repository.
- Thirdly, if something changes in the repository, it will automatically pull those changes and apply them in the cluster.
Best practice for GitHub repository
- Firstly, have a separate Git repository for application source code and application configuration.
- Secondly, a separate repository for system configuration.
As soon as the configuration file changes, ArgoCD in the cluster will immediately know about it because we configured it at the beginning to constantly monitor the changes and it will pull and apply changes in the cluster automatically.
How to create applications(Using User-Interface)
1. Set up ArgoCD on Kubernetes Cluster
(a) Firstly, create namespace
kubectl create namespace argocd
(b) Secondly, apply the YAML file(that installs all the necessary things)
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
(c) Thirdly, check pods
kubectl get pods -n argocd

2. Access Argocd UI
(a) Check services in argocd namespace
kubectl get service -n argocd



In my case the service type is LoadBalancer.
(b) Now, access the ArgoCD UI(in LoadBalancer simply copy the External-ip)



(c) Login into the ArgoCD server
The password for admin is stored in secret with the name- argocd-initial-admin-secret and also decodes the password.
kubectl get secrets -n argocd argocd-initial-admin-secret -o yaml
echo ZVF1ZHVZU21OR1RqTFViWg== | base64 --decode



Now, Sign In



Let’s start creating applications
Firstly, through UI
Click on +NEW APP and fill in the details like:-
- application name- demo
- project- default
- sync policy- manual
- repository URL- where your application is present
- path- in which the YAML files are located
- cluster URL- select the cluster URL you are using
- namespace- default
Leave the rest of the spaces empty for the time being









Moreover, for this outofsync status, we have to enable the auto-sync policy which is present inside the APP DETAILS by clicking on this demo application.






So, this is the first way of creating the application through UI.
Let’s, create the application using CLI
For the CLI, first, we have to install the argocd binary
wget https://github.com/argoproj/argo-cd/releases/download/v2.4.2/argocd-linux-amd64
Change the name of the binary(optional)
mv argocd-linux-amd64 argocd
Change permissions
chmod +x argocd
Move this file to another directory
sudo mv argocd /usr/local/bin
Now, type argocd help to check the available commands
Login to the server using your cluster IP and the port, in my case the service is LoadBalancer so I am using the External-IP
argocd login [external-ip]



Now, let’s create the application. Therefore, I am using the same example that I have used in the UI demo but with the different application name
argocd app create [app-name] --project [name] --repo [git repo URL] --path [app folder] --dest-namespace [namespace] --dest-server [server URL]
argocd app create demo1 --project default --repo https://github.com/Jasmine-Harit/gitops-certification-examples.git --path ./simple-app --dest-namespace default --dest-server https://kubernetes.default.svc
KEY POINTS:-
- app-name- is the name you want to give your app(like demo1)
- project- is the name of the project created or default
- app folder- the path to the configuration for the application in the repository
- git repo- it is the URL of the git repository where the configuration file is located
- dest-namespace- the name of the target namespace in the cluster where the application is deployed
- server URL- use https://kubernetes.default.svc to reference the same cluster where ArgoCD has been deployed






Now, let’s check the list of apps and the information of a particular app
argocd app list
argocd app get [app-name]
argocd app get demo1



Another way to create applications is by writing a YAML file
I am going to use the Gitlab example for this demo.
(a) Clone the repository and Create a YAML file
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argo-application
namespace: argocd
spec:
project: default
source:
repoURL: https://gitlab.com/jasmine.harit/argocd-app-config.git
targetRevision: HEAD
path: dev
destination:
server: https://kubernetes.default.svc
namespace: myapp
syncPolicy:
syncOptions:
- CreateNamespace=true
automated:
selfHeal: true
prune: true
Points to remember:- Inside automated, there are two things selfHeal is used for when you make changes directly to the cluster so argocd will automatically detect it and prune is used for when you remove or delete files from your repository that also argo will detect.
Now, apply this YAML using
kubectl apply -f [yaml file name]
kubectl apply -f application.yaml



CONCLUSION:-
Hence, these are the few different ways through which you can create your Argo applications and manage them easily.
HAPPY LEARNING!
REFERENCES:-
ArgoCD- Click
Demo- Click