Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Doel
Put an app into Git, let Argo CD deploy it, and see the GitOps promises with your own eyes: a change in Git is deployed by itself, a manual change in the cluster is undone (self-heal), a file you delete in Git is removed from the cluster (prune), and a rollback is just git revert.
Voordat je begint
- Argo CD installed (chapter Install and log in to Argo CD):
kubectl -n argocd get podsall Running, andargocd loginworks. - Make a public GitHub repository
gitops-labwith the folderapps/guestbook/that has a Deployment (nginx:1.26, 2 replicas) and a Service.
Taken
Vink een taak aan als hij klaar is. Alleen je browser onthoudt dit.
- Write an
AppProjectlabthat allows only your repository and only the namespaceguestbook. - Write an
Applicationguestbookin the projectlab: sourceapps/guestbook, destination namespaceguestbook,CreateNamespace=true, automated sync with prune and selfHeal. - Apply both with
kubectl(Argo CD manages them as normal objects) and wait until the app is Synced and Healthy. - In Git, change the image to
nginx:1.27and push. Watch Argo CD deploy it without any command. - Scale the deployment by hand to 5 replicas with
kubectl. Watch Argo CD set it back to 2. - Add a ConfigMap in Git with a sync-wave of
-1(so it is made before the Deployment), push, then delete it in Git and see it pruned. - Roll back the image change with
git revertand push.
Controleer je werk
Hints
Toon de hints
syncPolicy: automated: {prune: true, selfHeal: true}andsyncOptions: [CreateNamespace=true].- Argo CD checks Git every 3 minutes by default;
argocd app sync guestbookor a webhook makes it faster. - A sync wave is an annotation:
argocd.argoproj.io/sync-wave: "-1". - Do not use
argocd app rollbackwith auto-sync on: Git is the truth, so roll back in Git.
Oplossing
Toon de oplossing
- Project and application.lab-project.yaml
apiVersion: argoproj.io/v1alpha1 kind: AppProject metadata: name: lab namespace: argocd spec: sourceRepos: ["https://github.com/OWNER/gitops-lab.git"] destinations: - server: https://kubernetes.default.svc namespace: guestbook clusterResourceWhitelist: - group: "" kind: Namespaceguestbook-app.yamlapiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: guestbook namespace: argocd spec: project: lab source: repoURL: https://github.com/OWNER/gitops-lab.git targetRevision: main path: apps/guestbook destination: server: https://kubernetes.default.svc namespace: guestbook syncPolicy: automated: prune: true selfHeal: true syncOptions: [CreateNamespace=true] - A change in Git.
- Self-heal.
- Wave and prune.apps/guestbook/configmap.yaml
apiVersion: v1 kind: ConfigMap metadata: name: guestbook-config annotations: argocd.argoproj.io/sync-wave: "-1" data: GREETING: hello - Roll back in Git.
Mijn notities
Nog geen notities.