Bird
Raised Fist0
Kubernetesdevops~10 mins

GitOps with ArgoCD in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - GitOps with ArgoCD
Developer pushes code to Git repo
ArgoCD monitors Git repo
Detects changes in repo
ArgoCD syncs changes to Kubernetes cluster
Kubernetes applies new config/state
Cluster state matches Git repo state
ArgoCD reports status back
This flow shows how ArgoCD watches a Git repository for changes, then applies those changes automatically to a Kubernetes cluster, keeping cluster state in sync with Git.
Execution Sample
Kubernetes
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
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 sync guestbook
This sequence installs ArgoCD, creates an application linked to a Git repo, and syncs it to the Kubernetes cluster.
Process Table
StepActionEvaluationResult
1Create namespace 'argocd'Namespace 'argocd' does not existNamespace 'argocd' created
2Apply ArgoCD manifestsManifests validArgoCD components deployed in 'argocd' namespace
3Create ArgoCD app 'guestbook'Repo and path accessibleApp 'guestbook' registered in ArgoCD
4ArgoCD monitors Git repoNo changes yetApp status: Synced
5Push change to Git repo (e.g., update guestbook image)Change detected by ArgoCDApp status: OutOfSync
6Run 'argocd app sync guestbook'Sync command acceptedCluster updated to match Git repo
7Verify app statusCluster matches Git repoApp status: Synced
8ExitNo further changesProcess waits for next Git change
💡 No new changes in Git repo, ArgoCD waits for updates
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 5After Step 6Final
Namespace 'argocd'Not presentCreatedExistsExistsExistsExistsExists
ArgoCD app 'guestbook' statusNot presentNot presentNot presentSyncedOutOfSyncSyncedSynced
Cluster stateOld configOld configOld configOld configOld configUpdated to Git stateUpdated to Git state
Key Moments - 3 Insights
Why does ArgoCD show 'OutOfSync' after I push changes to Git?
Because ArgoCD detects that the cluster state no longer matches the Git repo state (see execution_table step 5). It waits for a sync command or automatic sync to update the cluster.
What happens if I don't run 'argocd app sync' after pushing changes?
The cluster remains out of sync with Git repo (execution_table step 5). ArgoCD will not apply changes until sync is triggered manually or auto-sync is enabled.
Why do we create a separate namespace 'argocd' before installing ArgoCD?
Namespaces isolate resources in Kubernetes. Creating 'argocd' namespace (step 1) keeps ArgoCD components organized and separate from other apps.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what is the ArgoCD app 'guestbook' status?
AOutOfSync
BUnknown
CSynced
DError
💡 Hint
Check the 'Result' column at step 5 in the execution_table.
At which step does the Kubernetes cluster update to match the Git repo?
AStep 5
BStep 6
CStep 3
DStep 7
💡 Hint
Look for the step where 'Cluster updated to match Git repo' appears in the execution_table.
If you skip creating the 'argocd' namespace, what will happen at step 2?
AArgoCD installs in default namespace
BNamespace is created automatically
CInstallation fails due to missing namespace
DArgoCD installs but with errors
💡 Hint
Refer to variable_tracker for 'Namespace argocd' status after step 1 and step 2.
Concept Snapshot
GitOps with ArgoCD:
- ArgoCD watches Git repo for changes
- Changes trigger sync to Kubernetes cluster
- Cluster state matches Git repo state
- Use 'argocd app sync' to apply changes
- Namespace isolates ArgoCD components
- Status shows sync state (Synced/OutOfSync)
Full Transcript
GitOps with ArgoCD means using Git as the single source of truth for Kubernetes configurations. Developers push changes to a Git repository. ArgoCD continuously monitors this repo. When it detects changes, it marks the application as OutOfSync. Running 'argocd app sync' applies those changes to the Kubernetes cluster, updating it to match the Git state. The cluster then reports back as Synced. ArgoCD runs in its own namespace for organization. This process automates deployment and keeps cluster state consistent with Git.

Practice

(1/5)
1. What is the main purpose of using ArgoCD in a Kubernetes environment with GitOps?
easy
A. To replace Kubernetes with a new container orchestration system
B. To manually deploy applications without using Git
C. To store container images in a private registry
D. To automatically sync Kubernetes cluster state with Git repository configurations

Solution

  1. Step 1: Understand GitOps concept

    GitOps uses Git as the single source of truth for application configurations.
  2. Step 2: Role of ArgoCD in GitOps

    ArgoCD automatically syncs Kubernetes cluster state to match the Git repo, ensuring deployments are consistent and automated.
  3. Final Answer:

    To automatically sync Kubernetes cluster state with Git repository configurations -> Option D
  4. Quick Check:

    GitOps = Auto-sync cluster with Git [OK]
Hint: Remember: ArgoCD syncs cluster state from Git automatically [OK]
Common Mistakes:
  • Thinking ArgoCD replaces Kubernetes
  • Believing ArgoCD deploys apps manually
  • Confusing ArgoCD with container registries
2. Which of the following is the correct ArgoCD CLI command to create an application named myapp syncing from Git repo https://github.com/example/repo.git with path k8s and target cluster https://kubernetes.default.svc?
easy
A. argocd app create myapp --repo https://github.com/example/repo.git --path k8s --dest-server https://kubernetes.default.svc --dest-namespace default
B. argocd create app myapp --repository https://github.com/example/repo.git --directory k8s --cluster https://kubernetes.default.svc
C. kubectl create app myapp --repo https://github.com/example/repo.git --path k8s
D. argocd app new myapp --repo-url https://github.com/example/repo.git --folder k8s --server https://kubernetes.default.svc

Solution

  1. Step 1: Identify correct ArgoCD CLI syntax

    The correct command uses argocd app create with flags --repo, --path, --dest-server, and --dest-namespace.
  2. Step 2: Compare options

    argocd app create myapp --repo https://github.com/example/repo.git --path k8s --dest-server https://kubernetes.default.svc --dest-namespace default matches the official syntax exactly. Others use incorrect commands or flags.
  3. Final Answer:

    argocd app create myapp --repo https://github.com/example/repo.git --path k8s --dest-server https://kubernetes.default.svc --dest-namespace default -> Option A
  4. Quick Check:

    Correct CLI syntax = argocd app create myapp --repo https://github.com/example/repo.git --path k8s --dest-server https://kubernetes.default.svc --dest-namespace default [OK]
Hint: Remember: 'argocd app create' plus repo, path, dest-server flags [OK]
Common Mistakes:
  • Using kubectl instead of argocd CLI
  • Wrong flag names like --repository or --folder
  • Incorrect command order or missing --dest-namespace
3. Given the following ArgoCD Application YAML snippet, what will happen when ArgoCD syncs this app?
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: sample-app
spec:
  source:
    repoURL: https://github.com/example/app-configs.git
    path: production
  destination:
    server: https://kubernetes.default.svc
    namespace: default
  syncPolicy:
    automated: {}
medium
A. ArgoCD will reject the app because syncPolicy is empty
B. ArgoCD will only show the app status but not deploy it automatically
C. ArgoCD will automatically deploy and keep the app in sync with the Git repo
D. ArgoCD will deploy the app once but not update it on Git changes

Solution

  1. Step 1: Understand syncPolicy automated

    The syncPolicy: automated: {} means ArgoCD will auto-sync changes from Git to cluster.
  2. Step 2: Effect on deployment

    ArgoCD will deploy the app initially and keep it updated automatically when Git changes.
  3. Final Answer:

    ArgoCD will automatically deploy and keep the app in sync with the Git repo -> Option C
  4. Quick Check:

    syncPolicy automated = auto deploy and sync [OK]
Hint: syncPolicy automated means auto deploy and keep in sync [OK]
Common Mistakes:
  • Thinking empty braces mean no automation
  • Assuming manual sync is required
  • Confusing syncPolicy with app rejection
4. You created an ArgoCD app but it shows OutOfSync status even after you committed changes to Git. Which of the following is the most likely cause?
medium
A. The app's syncPolicy is not set to automated, so manual sync is needed
B. The Git repository URL is incorrect and unreachable
C. The Kubernetes cluster is down and cannot apply changes
D. The app name in ArgoCD does not match the Git repo name

Solution

  1. Step 1: Understand OutOfSync status

    OutOfSync means cluster state differs from Git repo state.
  2. Step 2: Check syncPolicy effect

    If syncPolicy is not automated, ArgoCD won't auto-apply changes; manual sync is required.
  3. Final Answer:

    The app's syncPolicy is not set to automated, so manual sync is needed -> Option A
  4. Quick Check:

    OutOfSync + no automated sync = manual sync needed [OK]
Hint: OutOfSync often means no automated sync set [OK]
Common Mistakes:
  • Assuming cluster is down without checking
  • Blaming Git URL without error evidence
  • Thinking app name mismatch causes OutOfSync
5. You want to ensure that ArgoCD only deploys changes to your Kubernetes cluster after manual approval, but still track changes in Git automatically. Which configuration should you use in your ArgoCD Application YAML?
hard
A. Set syncPolicy: automated: {} to enable auto deploy
B. Omit syncPolicy and use manual sync to approve changes
C. Set syncPolicy: automated: null to disable auto deploy
D. Set syncPolicy: automated: { prune: true, selfHeal: true } for auto deploy with cleanup

Solution

  1. Step 1: Understand manual approval need

    To require manual approval before deployment, auto sync must be disabled.
  2. Step 2: Configure syncPolicy accordingly

    Omitting syncPolicy disables auto sync, so ArgoCD tracks Git but waits for manual sync.
  3. Final Answer:

    Omit syncPolicy and use manual sync to approve changes -> Option B
  4. Quick Check:

    No syncPolicy = manual approval required [OK]
Hint: No syncPolicy means manual sync only [OK]
Common Mistakes:
  • Using automated sync disables manual approval
  • Setting automated with prune/selfHeal still auto deploys
  • Setting automated: null is invalid syntax