Argo CD — Applications

Nandhabalan Marimuthu
3 min readJul 17, 2023

--

The Application CRD is the Kubernetes resource object representing a deployed application instance in an environment. Two key pieces of information define it:

  • source reference to the desired state in Git (repository, revision, path, environment)
  • destination reference to the target cluster and namespace. For the cluster one server or name can be used, but not both (which will result in an error). Under the hood when the server is missing, it is calculated based on the name and used for any operations.

ArgoCD Application creation ways:

  1. Declarative — using yaml file
  2. Web UI — entering specs in Web UI
  3. CLI — using commands

Declarative:

YAML

apiVersion: argoproj.io/v1alpha1 
kind: Application
metadata:
name: guestbook
spec:
project: default
source:
repo: https://github.com/argoproj/argocd-example-apps.git
path: guestbook
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
syncPolicy:
syncOptions:
- CreateNamespace=true

This application definition specifies the following:

  • The name of the application is guestbook.
  • The application is in the default project.
  • The application's source is the guestbook directory in the argocd-example-apps.git repository.
  • The target revision of the application is HEAD.
  • The destination of the application is the default namespace in the Kubernetes cluster running Argo CD.
  • The sync policy for the application specifies that Argo CD should automatically prune any resources that are no longer present in the source repository.

Here is a brief explanation of each of the fields in the application definition:

  • apiVersion specifies the API version of the application definition.
  • kind specifies the type of resource that the application definition is defining.
  • metadata contains the name and other metadata for the application.
  • spec specifies the configuration for the application.
  • source specifies the source of the application.
  • destination specifies the destination of the application.
  • syncPolicy specifies the sync policy for the application.

Apply the yaml file to create the application:

minikube kubectl - apply -f application.yaml

Using CLI:

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

This command creates an application named guestbook in the default project. The source of the application is the guestbook directory in the argocd-example-apps.git repository. The target revision of the application is HEAD. The destination of the application is the default namespace in the Kubernetes cluster running Argo CD. The sync policy for the application specifies that Argo CD should automatically prune any resources that are no longer present in the source repository.

Here is a brief explanation of each of the flags in the CLI command:

  1. — project specifies the project that the application should be created in.
  2. — repo specifies the URL of the Git repository that contains the application source code.
  3. — path specifies the path to the application source code in the Git repository.
  4. — target-revision specifies the revision of the application source code that should be deployed.
  5. — dest-server specifies the URL of the Kubernetes API server.
  6. — dest-namespace specifies the namespace in the Kubernetes cluster where the application should be deployed.
  7. — sync-policy specifies the sync policy for the application.

--

--