Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Lab 02: First Application

Uses the guestbook app from argoproj/argocd-example-apps. Needs lab 01 (logged in with the CLI, port-forward up).

Look at the source

git clone https://github.com/argoproj/argocd-example-apps.git
ls argocd-example-apps/guestbook
  • guestbook-ui-deployment.yaml and guestbook-ui-svc.yaml, plain manifests (image gcr.io/google-samples/gb-frontend, port 80)
  • To push changes fork it and use your fork as --repo

Create the app

argocd app create guestbook \
  --repo https://github.com/argoproj/argocd-example-apps.git \
  --path guestbook \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace default
argocd app list
argocd app get guestbook
  • --path is the dir in the repo, --dest-server is the target cluster API (this one = in-cluster)
  • Starts as OutOfSync / Missing: Git has the resources, the cluster doesn’t
  • Same as a declarative 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

Sync

argocd app manifests guestbook
argocd app diff guestbook
argocd app sync guestbook
argocd app wait guestbook --timeout 300
kubectl get all -n default -l app.kubernetes.io/instance=guestbook
kubectl port-forward svc/guestbook-ui 8081:80
  • diff is the live vs. desired state (everything is a diff before the first sync)
  • Sync status: Synced/OutOfSync. Health: Healthy/Progressing/Degraded/Missing
  • Resource tree in the UI shows the same thing

Drift vs. Git change

Drift in the cluster:

kubectl scale deployment guestbook-ui --replicas=2
argocd app get guestbook --refresh
argocd app diff guestbook
  • Live changes are seen almost immediately (the controller watches the cluster)
  • A plain argocd app sync guestbook puts replicas back to what Git says

Change in Git (fork):

  • Edit replicas in guestbook-ui-deployment.yaml, push
argocd app set guestbook --repo https://github.com/<user>/argocd-example-apps.git
argocd app get guestbook --refresh
argocd app sync guestbook
  • Git polling is every 3 minutes by default, --refresh or a webhook skips the wait

History and rollback

argocd app history guestbook
argocd app rollback guestbook <ID>
  • Rollback only works with auto-sync off, it would just be synced forward again otherwise
  • Rollback deploys a previous revision but Git still points at the new one, so the app shows OutOfSync
  • Better rollback is git revert

Sync options:

argocd app sync guestbook --dry-run
argocd app sync guestbook --prune
argocd app sync guestbook --resource apps:Deployment:guestbook-ui
  • --prune deletes resources that are no longer in Git
  • --resource is GROUP:KIND:NAME

Cleanup

argocd app delete guestbook --yes
kubectl get all -n default -l app.kubernetes.io/instance=guestbook
  • Delete cascades to the resources by default (finalizer), --cascade=false leaves them behind
  • ctrl-c the port-forward