ЁЯПл The SchoolтА║ЁЯдЦ ArgoCDтА║ЁЯУД рдзрдбрд╛ 07 тАФ рдкрд╣рд┐рд▓реЗ Application: рдкреНрд▓реЕрди-рд╡рд╣реАрдЪреЗ рдПрдХ рдкрд╛рди
ЁЯЦ╝я╕П See the drawing + lab ЁЯПа Course home ЁЯМ┐ Branch on GitHub тЬПя╕П View source
ЁЯЦ╝я╕П рдЖрдХреГрддреА рдЖрдгрд┐ labThe drawing + lab рдкреВрд░реНрдг рдкрд╛рдирд╛рд╡рд░ рдЙрдШрдбрд╛ тЖЧOpen full page тЖЧ

ЁЯУД рдзрдбрд╛ 07 тАФ рдкрд╣рд┐рд▓реЗ Application: рдкреНрд▓реЕрди-рд╡рд╣реАрдЪреЗ рдПрдХ рдкрд╛рди

ЁЯУН рддреБрдореНрд╣реА рдЗрдереЗ рдЖрд╣рд╛рдд: 12 рдкреИрдХреА рдзрдбрд╛ 07 ┬╖ рдорд╛рдЧреЗ: lesson-06-install-argocd ┬╖ рдкреБрдвреЗ: lesson-08-sync-policies


ЁЯУж рдпрд╛ рдмреНрд░рдБрдЪрдордзреНрдпреЗ рдХрд╛рдп рдЖрд╣реЗ

рдзрдбреЗ 01тАУ06, рдЖрдгрд┐ рддреНрдпрд╛рд╕реЛрдмрдд рддреЛ рдХреНрд╖рдг рдЬреЗрд╡реНрд╣рд╛ рд╕рдЧрд│реЗ рдЙрдордЧрддреЗ: рдПрдХ Application resource рдЬреЗ ArgoCD рдХрдбреВрди рдпрд╛ repo рдЪрд╛ k8s/ folder deploy рдХрд░реВрди рдШреЗрддреЗ тАФ рдЖрдгрд┐ рддреНрдпрд╛рдирдВрддрд░ рддреБрдореНрд╣реА рдкреБрдиреНрд╣рд╛ рдХрдзреАрдЪ app kubectl apply рдХрд░рдд рдирд╛рд╣реА. рдЦрд░реА file:

ЁЯзТ 5 рд╡рд░реНрд╖рд╛рдВрдЪреНрдпрд╛ рдореБрд▓рд╛рд▓рд╛ рд╕рдордЬрд╛рд╡рд▓реНрдпрд╛рд╕рд╛рд░рдЦреЗ

Robot рдХрд╛рдорд╛рд╡рд░ рдареЗрд╡рд▓реЗрд▓рд╛ рдЖрд╣реЗ рдкрдг рд░рд┐рдХрд╛рдорд╛ рдмрд╕рд▓реЗрд▓рд╛ рдЖрд╣реЗ. рддреБрдореНрд╣реА рддреНрдпрд╛рд▓рд╛ рдкреНрд▓реЕрди-рд╡рд╣реАрдЪреЗ рдПрдХ рдкрд╛рди ЁЯУД рджреЗрддрд╛, рдЬреНрдпрд╛рд╡рд░ рдиреЗрдордХреНрдпрд╛ рддреАрди рдЧреЛрд╖реНрдЯреА рдЖрд╣реЗрдд:

  1. рдХреЛрдгрддреА рд╡рд╣реА ЁЯУЦ тАФ "рдЧреНрд░рдВрдерд╛рд▓рдпрд╛рддрд▓реА learn-argocd-school рдирд╛рд╡рд╛рдЪреА рд╡рд╣реА" (git repoURL).
  2. рдХреЛрдгрддрд╛ рдзрдбрд╛ тАФ "k8s/ рд╣рд╛ рдзрдбрд╛ рд╡рд╛рдЪрд╛, main рдЖрд╡реГрддреНрддреА" (path рдЖрдгрд┐ targetRevision).
  3. рдХреЛрдгрддреА рдЦреЛрд▓реА ЁЯЪк тАФ "рдпрд╛ рдЗрдорд╛рд░рддреАрддрд▓рд╛ gitops-school рд╡рд░реНрдЧ рддреНрдпрд╛рдЪреНрдпрд╛рд╢реА рдЬреБрд│рд╡рд╛" (destination).

Robot рдкрд╛рди рд╡рд╛рдЪрддреЛ, рдЧреНрд░рдВрдерд╛рд▓рдпрд╛рдд рдЬрд╛рддреЛ, рддреЛ рдзрдбрд╛ рдШреЗрдКрди рдпреЗрддреЛ, рдЦреЛрд▓реАрдд рдЬрд╛рддреЛтАж рдЖрдгрд┐ рддреА рдмрд╛рдВрдзрддреЛ: namespace, deployment, service, pods. рддреБрдореНрд╣реА рдХрд╛рд╣реАрдЪ рд╡рд╛рд╣реВрди рдиреЗрд▓реЗ рдирд╛рд╣реА. ЁЯОТтЭМ

рдЖрдгрд┐ рдЦрд░реА рдЬрд╛рджреВ: рд╣реЗ рдкрд╛рди рдХрдзреАрдЪ рдХрд╛рд▓рдмрд╛рд╣реНрдп рд╣реЛрдд рдирд╛рд╣реА. Robot рджрд░ рдХрд╛рд╣реА рдорд┐рдирд┐рдЯрд╛рдВрдиреА, рдХрд╛рдпрдо, рддреЛ рдзрдбрд╛ рдкреБрдиреНрд╣рд╛ рд╡рд╛рдЪрддреЛ. рдзрдбрд╛ рдмрджрд▓рдгреЗ (git commit) рд╣рд╛рдЪ рдЖрддрд╛ рддреА рдЦреЛрд▓реА рдмрджрд▓рдгреНрдпрд╛рдЪрд╛ рдПрдХрдореЗрд╡ рдорд╛рд░реНрдЧ рдЖрд╣реЗ тАФ рдЖрдгрд┐ рддреБрдореНрд╣рд╛рд▓рд╛ рдиреЗрдордХреЗ рд╣реЗрдЪ рд╣рд╡реЗ рдЖрд╣реЗ.

ЁЯЧ║я╕П рдЖрдХреГрддреА

flowchart LR
    app["ЁЯУД Application<br/>repoURL: learn-argocd-school<br/>path: k8s/ ┬╖ rev: main<br/>dest: gitops-school"]
    argo["ЁЯдЦ ArgoCD"]
    book["ЁЯУЦ git: the k8s/ chapter<br/>deployment + service + ns"]
    room["ЁЯЪк gitops-school<br/>ЁЯкСЁЯкС hello-school pods LIVE"]
    app -->|"1 kubectl apply -f argocd/"| argo
    argo -->|"2 clones and renders"| book
    argo -->|"3 creates everything"| room

тЭУ рдХрд╛рдп

ЁЯдФ рдХрд╛

рд╣реА рдПрдХрдЪ file рдпрд╛рдВрдЪреА рдЬрд╛рдЧрд╛ рдШреЗрддреЗ: рддреБрдордЪрд╛ kubectl apply рд╡рд┐рдзреА, pipeline рдЪрд╛ deploy job, "рдХрд╛рдп deploy рдЭрд╛рд▓реЗ рдЖрд╣реЗ?" рдЪреА spreadsheet, рдЖрдгрд┐ рдкрд╣рд╛рдЯреЗ 3 рд╡рд╛рдЬрддрд╛рдЪреА "prod git рдордзреНрдпреЗ рдЖрд╣реЗ рддрд╕реЗрдЪ рдЖрд╣реЗ рдХрд╛?" рд╣реА рд╢рдВрдХрд╛. рдПрдХ рдкрд╛рди тЖТ рддреА рдЦреЛрд▓реА рдХрд╛рдпрдордЪреА robot рдЪреНрдпрд╛ рддрд╛рдмреНрдпрд╛рдд.

тЬЕ рдЦрдбреНрдбрд╛ 2 рдмреБрдЬрд▓рд╛. Cluster рдЪреНрдпрд╛ рдмрд╛рд╣реЗрд░ рдЖрддрд╛ рдХреЛрдгрд╛рдХрдбреЗрд╣реА deployment credentials рдирд╛рд╣реАрдд: robot рдЖрддреВрдирдЪ рд╡рд╣реА pull рдХрд░рддреЛ, рдлрдХреНрдд рддреНрдпрд╛рдЪреЗ рдЧреНрд░рдВрдерд╛рд▓рдп рдХрд╛рд░реНрдб (git рд▓рд╛ read access) рд╡рд╛рдкрд░реВрди. рддреБрдордЪреНрдпрд╛ CI рдордзреВрди kubeconfig рдкреВрд░реНрдгрдкрдгреЗ рдХрд╛рдвреВрди рдЯрд╛рдХрддрд╛ рдпреЗрддреЗ.

ЁЯФз рдХрд╕реЗ (file, рдЯрд┐рдкрд╛рдВрд╕рд╣)

spec:
  source:
    repoURL: https://github.com/BaluRaut/learn-argocd-school.git
    targetRevision: main       # which edition to follow (branch/tag)
    path: k8s                  # which chapter (folder of manifests)
  destination:
    server: https://kubernetes.default.svc   # this very cluster
    namespace: gitops-school
  syncPolicy:
    automated: { prune: true, selfHeal: true }   # lesson 08 explains these
    syncOptions: [CreateNamespace=true]

ЁЯзк рдХрд░реВрди рдкрд╛рд╣рд╛

# clean slate makes the magic obvious тАФ delete the hand-deployed app first:
kubectl delete namespace gitops-school --ignore-not-found

# hand the robot the page:
kubectl apply -f argocd/application.yaml

# watch it work (UI: the hello-school app appears and turns green), or:
kubectl -n argocd get application hello-school -w    # OutOfSync тЖТ Synced; Ctrl+C
kubectl -n gitops-school get all                     # the room, built by the robot ЁЯОЙ

# proof you're out of the loop now:
kubectl -n gitops-school delete deployment hello-school
kubectl -n gitops-school get deploy -w               # ...it comes BACK. (lesson 08 tells you why)

тЬЕ рддрдкрд╛рд╕рд╛ тАФ рддреБрдореНрд╣рд╛рд▓рд╛ рдХрд╛рдп рджрд┐рд╕рд╛рдпрд▓рд╛ рд╣рд╡реЗ

kubectl -n argocd get application hello-school тЖТ рдПрдХ-рджреЛрди рдорд┐рдирд┐рдЯрд╛рдВрдд SYNC STATUS: Synced, HEALTH STATUS: Healthy. рдЖрдзреА рддреЗ OutOfSync / Progressing рдордзреВрди рдЬрд╛рддреЗ тАФ рддреЗ рд╕рдВрдХреНрд░рдордг рд╣рд╛рдЪ рддрд░ рдзрдбрд╛ рдЖрд╣реЗ. kubectl -n gitops-school get all robot рдиреЗ рдмрд╛рдВрдзрд▓реЗрд▓реЗ namespace, Deployment, Service рдЖрдгрд┐ рджреЛрди pods рджрд╛рдЦрд╡рддреЗ; UI рдордзреНрдпреЗ tile рд╣рд┐рд░рд╡реА рдЕрд╕рддреЗ, Application тЖТ Deployment тЖТ ReplicaSet тЖТ Pods рдпрд╛ tree рд╕рд╣.

ЁЯз╣ рд╕рд╛рдлрд╕рдлрд╛рдИ

рдзрдбреЗ 08тАУ12 рд╕рд╛рдареА Application рд░рд╛рд╣реВ рджреНрдпрд╛. рдирдВрддрд░ рддреЗ рдХрд╛рдврддрд╛рдирд╛: kubectl -n argocd delete application hello-school deploy рдЭрд╛рд▓реЗрд▓реЗ resources рддрд╕реЗрдЪ рдареЗрд╡рддреЗ, рдЬреЛрдкрд░реНрдпрдВрдд Application рд╡рд░ resources-finalizer.argocd.argoproj.io finalizer рдирд╕рддреЛ (argocd app delete hello-school --cascade рддреЛ рдЬреЛрдбрддреЗ). рдордЧ рдЙрд░рд▓реЗрд▓реНрдпрд╛ рдХрд╢рд╛рд╕рд╛рдареАрд╣реА kubectl delete namespace gitops-school.

тЪая╕П рдиреЗрд╣рдореАрдЪреНрдпрд╛ рдЪреБрдХрд╛

ЁЯПн рдкреНрд░рддреНрдпрдХреНрд╖ рд╡рд╛рдкрд░рд╛рдд рд╣реЗ рдХрд╛ рдорд╣рддреНрддреНрд╡рд╛рдЪреЗ рдЖрд╣реЗ: Application рдлрдХреНрдд YAML рдЖрд╣реЗ, рдореНрд╣рдгреВрди рддреЗрд╣реА git рдордзреНрдпреЗ рд░рд╛рд╣рддреЗ (app-of-apps, рдзрдбрд╛ 11) тАФ Applications рд╕реБрджреНрдзрд╛ рдХреЛрдгреА рд╣рд╛рддрд╛рдиреЗ kubectl apply рдХрд░рдд рдирд╛рд╣реА. Private repos рдирд╛ repo credential (deploy key рдХрд┐рдВрд╡рд╛ GitHub App) рд▓рд╛рдЧрддреЗ, рдЬреЗ CI рдордзреНрдпреЗ рдирд╡реНрд╣реЗ рддрд░ cluster рдордзреНрдпреЗ рд╕рд╛рдард╡рд▓реЗ рдЬрд╛рддреЗ.

тПня╕П рдкреБрдвреЗ

automated, prune, selfHeal тАФ robot рдЪреЗ рдШрд░рдЪреЗ рдирд┐рдпрдо, рдЖрдгрд┐ рддреЗ рдХрдзреА рд╕реИрд▓ рдХрд░рд╛рдпрдЪреЗ.

git checkout lesson-08-sync-policies

ЁЯУД Lesson 07 тАФ The first Application: one page of the plan book

ЁЯУН You are here: Lesson 07 of 12 ┬╖ Previous: lesson-06-install-argocd ┬╖ Next: lesson-08-sync-policies


ЁЯУж What's in this branch

Lessons 01тАУ06, plus the moment it all clicks: an Application resource that makes ArgoCD deploy this repo's k8s/ folder тАФ and from then on, you never kubectl apply the app again. Real file:

ЁЯзТ Explain like I'm 5

The robot is hired but idle. You hand it one page of the plan book ЁЯУД with exactly three facts on it:

  1. Which book ЁЯУЦ тАФ "the one in the library called learn-argocd-school" (the git repoURL).
  2. Which chapter тАФ "read the k8s/ chapter, main edition" (the path and targetRevision).
  3. Which room ЁЯЪк тАФ "make classroom gitops-school in THIS building match it" (the destination).

The robot reads the page, walks to the library, fetches the chapter, walks to the roomтАж and builds it: namespace, deployment, service, pods. You never carried anything. ЁЯОТтЭМ

And the deep magic: the page never expires. The robot re-reads the chapter every few minutes, forever. Editing the chapter (a git commit) is now the ONLY way anyone changes that room тАФ which is exactly what you want.

ЁЯЧ║я╕П Diagram

flowchart LR
    app["ЁЯУД Application<br/>repoURL: learn-argocd-school<br/>path: k8s/ ┬╖ rev: main<br/>dest: gitops-school"]
    argo["ЁЯдЦ ArgoCD"]
    book["ЁЯУЦ git: the k8s/ chapter<br/>deployment + service + ns"]
    room["ЁЯЪк gitops-school<br/>ЁЯкСЁЯкС hello-school pods LIVE"]
    app -->|"1 kubectl apply -f argocd/"| argo
    argo -->|"2 clones and renders"| book
    argo -->|"3 creates everything"| room

тЭУ What

ЁЯдФ Why

This single file replaces: your kubectl apply ritual, the pipeline's deploy job, the "what's deployed?" spreadsheet, and the 3 AM "is prod what's in git?" doubt. One page тЖТ the robot owns that room forever.

тЬЕ Gap 2 closed. Nothing outside the cluster holds deployment credentials any more: the robot pulls the book from inside, using only its library card (read access to git). Your CI can lose its kubeconfig entirely.

ЁЯФз How (the file, annotated)

spec:
  source:
    repoURL: https://github.com/BaluRaut/learn-argocd-school.git
    targetRevision: main       # which edition to follow (branch/tag)
    path: k8s                  # which chapter (folder of manifests)
  destination:
    server: https://kubernetes.default.svc   # this very cluster
    namespace: gitops-school
  syncPolicy:
    automated: { prune: true, selfHeal: true }   # lesson 08 explains these
    syncOptions: [CreateNamespace=true]

ЁЯзк Try it

# clean slate makes the magic obvious тАФ delete the hand-deployed app first:
kubectl delete namespace gitops-school --ignore-not-found

# hand the robot the page:
kubectl apply -f argocd/application.yaml

# watch it work (UI: the hello-school app appears and turns green), or:
kubectl -n argocd get application hello-school -w    # OutOfSync тЖТ Synced; Ctrl+C
kubectl -n gitops-school get all                     # the room, built by the robot ЁЯОЙ

# proof you're out of the loop now:
kubectl -n gitops-school delete deployment hello-school
kubectl -n gitops-school get deploy -w               # ...it comes BACK. (lesson 08 tells you why)

тЬЕ Verify тАФ what you should see

kubectl -n argocd get application hello-school тЖТ SYNC STATUS: Synced, HEALTH STATUS: Healthy within a minute or two. It passes through OutOfSync / Progressing first тАФ that transition is the lesson. kubectl -n gitops-school get all shows the namespace, Deployment, Service and two pods the robot built; in the UI the tile is green with the tree Application тЖТ Deployment тЖТ ReplicaSet тЖТ Pods.

ЁЯз╣ Clean up

Keep the Application for lessons 08тАУ12. Removing it later: kubectl -n argocd delete application hello-school leaves the deployed resources in place unless the Application carries the resources-finalizer.argocd.argoproj.io finalizer (argocd app delete hello-school --cascade adds it). Then kubectl delete namespace gitops-school for anything left.

тЪая╕П Common mistakes

ЁЯПн Why this matters in production: the Application is just YAML, so it lives in git too (app-of-apps, lesson 11) тАФ nobody kubectl applys Applications by hand either. Private repos need a repo credential (deploy key or GitHub App) stored in the cluster, not in CI.

тПня╕П Next

automated, prune, selfHeal тАФ the robot's house rules, and when to loosen them.

git checkout lesson-08-sync-policies
тЖР Previousinstall argocdNext тЖТsync policies

This page is the lesson's README from the lesson-07-first-application branch, shown here so the whole School stays on one site. Code files open on GitHub at the same branch.