Skip to main content

Create an Application


Table of Contents​

  1. Via the Web interface
  2. Via the CLI
  3. Via declarative YAML
  4. With Helm
  5. With Kustomize
  6. Hands-on exercises

1 - Via the Web interface​

Steps​

  1. Open the Argo CD UI (https://localhost:8080)
  2. Click + NEW APP
  3. Fill in the form:
FieldValue
Application Nameguestbook
Projectdefault
Sync PolicyManual
Repository URLhttps://github.com/argoproj/argocd-example-apps.git
Pathguestbook
Cluster URLhttps://kubernetes.default.svc
Namespacedefault
  1. Click CREATE
  2. Click SYNC to deploy

Workflow snapshot​

πŸ” Back to table of contents​


2 - Via the CLI​

Create an application​

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

# VΓ©rifier
argocd app list

# Synchroniser
argocd app sync guestbook

Common options​

# Avec auto-sync
argocd app create my-app \
--repo https://github.com/org/gitops.git \
--path apps/my-app \
--dest-server https://kubernetes.default.svc \
--dest-namespace production \
--sync-policy automated \
--auto-prune \
--self-heal

# Avec une branche spΓ©cifique
argocd app create my-app \
--revision main \
...

# Avec un tag
argocd app create my-app \
--revision v1.2.3 \
...

Useful commands​

# Voir le dΓ©tail
argocd app get guestbook

# Voir les ressources
argocd app resources guestbook

# Voir l'historique
argocd app history guestbook

# Supprimer
argocd app delete guestbook

πŸ” Back to table of contents​


3 - Via declarative YAML​

Basic Application​

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
namespace: argocd
spec:
project: default

source:
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: HEAD
path: guestbook

destination:
server: https://kubernetes.default.svc
namespace: default

Application with Sync Policy​

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default

source:
repoURL: https://github.com/org/gitops.git
targetRevision: main
path: apps/my-app

destination:
server: https://kubernetes.default.svc
namespace: production

syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- PruneLast=true

Apply​

kubectl apply -f application.yaml

Best practices​

metadata:
# Finalizer pour cleanup propre
finalizers:
- resources-finalizer.argocd.argoproj.io

# Labels pour organisation
labels:
app.kubernetes.io/name: my-app
team: backend
env: production

πŸ” Back to table of contents​


4 - With Helm​

From a Helm repository​

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: nginx
namespace: argocd
spec:
project: default

source:
repoURL: https://charts.bitnami.com/bitnami
chart: nginx
targetRevision: 15.0.0
helm:
values: |
replicaCount: 3
service:
type: ClusterIP
resources:
requests:
memory: 128Mi
cpu: 100m

destination:
server: https://kubernetes.default.svc
namespace: web

From a Git repo containing the chart​

spec:
source:
repoURL: https://github.com/org/gitops.git
path: charts/my-app
targetRevision: HEAD
helm:
valueFiles:
- values.yaml
- values-prod.yaml
parameters:
- name: image.tag
value: v1.2.3

Helm with external values​

spec:
source:
repoURL: https://github.com/org/gitops.git
path: charts/my-app
helm:
valueFiles:
- values.yaml
# Fichier depuis un autre path
- $values/environments/prod/values.yaml
sources:
- repoURL: https://github.com/org/config.git
ref: values

πŸ” Back to table of contents​


5 - With Kustomize​

Typical structure​

apps/my-app/
β”œβ”€β”€ base/
β”‚ β”œβ”€β”€ kustomization.yaml
β”‚ β”œβ”€β”€ deployment.yaml
β”‚ └── service.yaml
└── overlays/
β”œβ”€β”€ dev/
β”‚ └── kustomization.yaml
└── prod/
└── kustomization.yaml

Kustomize Application​

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app-prod
namespace: argocd
spec:
project: default

source:
repoURL: https://github.com/org/gitops.git
path: apps/my-app/overlays/prod
targetRevision: HEAD
kustomize:
images:
- name: my-app
newTag: v1.2.3

destination:
server: https://kubernetes.default.svc
namespace: production

Image overrides​

spec:
source:
kustomize:
images:
- name: nginx
newName: my-registry/nginx
newTag: custom-tag
namePrefix: prod-
nameSuffix: -v2
commonLabels:
env: production

πŸ” Back to table of contents​


6 - Hands-on exercises​

Exercise 1: Deploy guestbook​

# CrΓ©er l'application
argocd app create guestbook \
--repo https://github.com/argoproj/argocd-example-apps.git \
--path guestbook \
--dest-server https://kubernetes.default.svc \
--dest-namespace default

# Synchroniser
argocd app sync guestbook

# VΓ©rifier
kubectl get pods -n default
argocd app get guestbook

Exercise 2: Deploy with YAML​

# my-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: helm-guestbook
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/argoproj/argocd-example-apps.git
path: helm-guestbook
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
kubectl apply -f my-app.yaml

Quiz​

Q1. What is the difference between path and chart in source?

Answer
  • path: Path to a folder in a Git repo
  • chart: Name of a chart in a Helm repository

You use path for local manifests (YAML, Kustomize, local chart) and chart for charts from a Helm registry.

πŸ” Back to table of contents​


Key takeaways​

  • 3 methods: UI, CLI, declarative YAML
  • Always specify source and destination
  • Helm: registry repoURL + chart + version
  • Kustomize: path to the overlay
  • Use labels for organization

← Previous chapter | Next chapter: Sync Strategies β†’