Aller au contenu principal

Créer une Application


Table des matières

  1. Via l'interface Web
  2. Via le CLI
  3. Via YAML déclaratif
  4. Avec Helm
  5. Avec Kustomize
  6. Exercices pratiques

1 - Via l'interface Web

Étapes

  1. Ouvrir l'UI Argo CD (https://localhost:8080)
  2. Cliquer sur + NEW APP
  3. Remplir le formulaire :
ChampValeur
Application Nameguestbook
Projectdefault
Sync PolicyManual
Repository URLhttps://github.com/argoproj/argocd-example-apps.git
Pathguestbook
Cluster URLhttps://kubernetes.default.svc
Namespacedefault
  1. Cliquer sur CREATE
  2. Cliquer sur SYNC pour déployer

Capture du workflow

🔝 Retour à la table des matières


2 - Via le CLI

Créer une 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

Options courantes

# 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 \
...

Commandes utiles

# 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

🔝 Retour à la table des matières


3 - Via YAML déclaratif

Application basique

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 avec 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

Appliquer

kubectl apply -f application.yaml

Bonnes pratiques

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

🔝 Retour à la table des matières


4 - Avec Helm

Depuis un 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

Depuis un Git repo contenant le 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 avec values externes

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

🔝 Retour à la table des matières


5 - Avec Kustomize

Structure type

apps/my-app/
├── base/
│ ├── kustomization.yaml
│ ├── deployment.yaml
│ └── service.yaml
└── overlays/
├── dev/
│ └── kustomization.yaml
└── prod/
└── kustomization.yaml

Application Kustomize

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

Override d'images

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

🔝 Retour à la table des matières


6 - Exercices pratiques

Exercice 1 : Déployer 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

Exercice 2 : Déployer avec 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. Quelle est la différence entre path et chart dans source ?

Réponse
  • path : Chemin vers un dossier dans un repo Git
  • chart : Nom d'un chart dans un Helm repository

On utilise path pour les manifests locaux (YAML, Kustomize, chart local) et chart pour les charts depuis un registry Helm.

🔝 Retour à la table des matières


Points clés à retenir

  • 3 méthodes : UI, CLI, YAML déclaratif
  • Toujours spécifier source et destination
  • Helm : repoURL du registry + chart + version
  • Kustomize : path vers l'overlay
  • Utiliser des labels pour l'organisation

← Chapitre précédent | Chapitre suivant : Sync Strategies →