> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo GitOps Delivery with ArgoCD CLI

> Demonstrates using the Argo CD CLI to create, sync, and automate Kubernetes GitOps deployments with self healing, auto prune, monitoring, and CI/CD automation

This lesson shows how to administer Argo CD using the CLI to perform the same tasks normally done in the web UI. You will:

* Log in to Argo CD via the CLI
* Create an application from a Git repo
* Sync and monitor application status
* Enable automated sync, self-heal, and auto-prune
* Test self-heal behavior and observe Kubernetes events
* Use `argocd app wait` to block until sync completes

This is useful for scripting GitOps operations, automation, and CI/CD integrations.

## Login to Argo CD

In this environment Argo CD is exposed via a NodePort on `localhost:30080`. Authenticate with the admin account from the CLI:

```bash theme={null}
argocd login localhost:30080 \
  --username admin \
  --password admin123 \
  --insecure \
  --plaintext
```

Console output:

```console theme={null}
'admin:login' logged in successfully
Context 'localhost:30080' updated
```

This login uses plaintext credentials and `--insecure` (disables TLS verification). It's acceptable for lab environments but should never be used in production. For production, use secure credentials and TLS.

## Create the application

Create an Argo CD Application named `web-frontend` that points to the example repository and `guestbook` path:

```bash theme={null}
argocd app create web-frontend \
  --repo https://github.com/argoproj/argocd-example-apps.git \
  --path guestbook \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace applications
```

Console output:

```console theme={null}
application 'web-frontend' created
```

Check the application status (initially Manual sync; resources are not yet deployed):

```bash theme={null}
argocd app get web-frontend
```

Representative output (initial state):

```console theme={null}
Name:            argocd/web-frontend
Project:         default
Server:          https://kubernetes.default.svc
Namespace:       applications
URL:             http://localhost:30080/applications/web-frontend
Source:
  - Repo: https://github.com/argoproj/argocd-example-apps.git
    Path: guestbook
SyncWindow:      Sync Allowed
Sync Policy:     Manual
Sync Status:     OutOfSync from (723b86e)
Health Status:   Missing

GROUP  KIND        NAMESPACE     NAME           STATUS      HEALTH  HOOK  MESSAGE
apps   Service     applications  guestbook-ui   OutOfSync   Missing
apps   Deployment  applications  guestbook-ui   OutOfSync   Missing
```

Confirm there are no Kubernetes resources deployed in the `applications` namespace yet:

```bash theme={null}
kubectl get pods -n applications
```

Output:

```console theme={null}
No resources found in applications namespace.
```

## Sync the application

Deploy the resources defined in Git by triggering a sync:

```bash theme={null}
argocd app sync web-frontend
```

Console output (sync events and final state):

```console theme={null}
TIMESTAMP                   GROUP       KIND        NAMESPACE     NAME          STATUS      HEALTH   HOOK  MESSAGE
2026-04-05T17:26:07+00:00   apps        Deployment  applications  guestbook-ui   OutOfSync   Missing
2026-04-05T17:26:07+00:00   apps        Service     applications  guestbook-ui   OutOfSync   Missing
2026-04-05T17:26:08+00:00   apps        Service     applications  guestbook-ui   OutOfSync   Missing            service/guestbook-ui created
2026-04-05T17:26:08+00:00   apps        Deployment  applications  guestbook-ui   OutOfSync   Missing            deployment.apps/guestbook-ui created

Name:           argocd/web-frontend
Project:        default
Server:         https://kubernetes.default.svc
Namespace:      applications
URL:            http://localhost:30080/applications/web-frontend
Source:
  - Repo: https://github.com/argoproj/argocd-example-apps.git
    Path: guestbook
SyncWindow:     Sync Allowed
Sync Policy:    Manual
Sync Status:    Synced to (723b86e)
Health Status:  Progressing

Operation:      Sync
Sync Revision:  723b86e01bea11dcf72316cb172868fcbf05d69e
Phase:          Succeeded
Start:          2026-04-05 17:26:07 +0000 UTC
Finished:       2026-04-05 17:26:08 +0000 UTC
Duration:       1s
Message:        successfully synced (all tasks run)

GROUP  KIND        NAMESPACE     NAME           STATUS      HEALTH     HOOK  MESSAGE
apps   Service     applications  guestbook-ui   Synced      Healthy           service/guestbook-ui created
apps   Deployment  applications  guestbook-ui   Synced      Progressing       deployment.apps/guestbook-ui created
```

Now verify the Pods are running in the `applications` namespace:

```bash theme={null}
kubectl get pods -n applications
```

Output:

```console theme={null}
NAME                                READY   STATUS    RESTARTS   AGE
guestbook-ui-6595f948db-5ndrw       1/1     Running   0          35s
```

## Enable automated sync, self-heal, and auto-prune

By default Argo CD Applications use Manual sync. To have Argo CD automatically reconcile the live cluster to the Git state, and to prune removed resources, enable the following settings.

Set automated sync:

```bash theme={null}
argocd app set web-frontend --sync-policy automated
```

Enable self-heal (auto-reconcile out-of-band changes):

```bash theme={null}
argocd app set web-frontend --self-heal
```

Enable auto-prune (remove resources that were deleted from Git):

```bash theme={null}
argocd app set web-frontend --auto-prune
```

Verify the application now shows Automated (Prune) and self-heal behavior:

```bash theme={null}
argocd app get web-frontend
```

Representative output:

```console theme={null}
Name:               argocd/web-frontend
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          applications
URL:                http://localhost:30080/applications/web-frontend
Source:
  - Repo:            https://github.com/argoproj/argocd-example-apps.git
    Path:            guestbook
SyncWindow:         Sync Allowed
Sync Policy:        Automated (Prune)
Sync Status:        Synced to (723b86e)
Health Status:      Healthy

GROUP   KIND        NAMESPACE     NAME           STATUS  HEALTH   HOOK    MESSAGE
apps    Deployment  applications  guestbook-ui    Synced  Healthy          deployment.apps/guestbook-ui configured
apps    Service     applications  guestbook-ui    Synced  Healthy
```

## Test self-heal behavior

Simulate an out-of-band change by scaling the deployment directly with kubectl:

```bash theme={null}
kubectl scale deployment guestbook-ui -n applications --replicas=5
```

Console output:

```console theme={null}
deployment.apps/guestbook-ui scaled
```

Argo CD (with automated sync + self-heal) should detect the divergence and revert the replica count back to what's declared in Git. Check status and pods again:

```bash theme={null}
argocd app get web-frontend
kubectl get pods -n applications
```

Representative outputs:

```console theme={null}
# argocd app get web-frontend
Sync Policy:        Automated (Prune)
Sync Status:        Synced to (723b86e)
Health Status:      Healthy

GROUP   KIND        NAMESPACE     NAME           STATUS  HEALTH   HOOK    MESSAGE
apps    Deployment  applications  guestbook-ui    Synced  Healthy          deployment.apps/guestbook-ui configured
apps    Service     applications  guestbook-ui    Synced  Healthy
```

```console theme={null}
# kubectl get pods -n applications
NAME                                READY   STATUS    RESTARTS   AGE
guestbook-ui-6595f948db-5ndrw       1/1     Running   0          2m54s
```

Describe the Deployment to view events that show Kubernetes scaling up and then Argo CD reverting the change:

```bash theme={null}
kubectl describe deployment guestbook-ui -n applications
```

Relevant events excerpt:

```console theme={null}
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ---    ----                   -------
  Normal  ScalingReplicaSet  3m18s  deployment-controller  Scaled up replica set guestbook-ui-6595f948db from 0 to 1
  Normal  ScalingReplicaSet  52s    deployment-controller  Scaled up replica set guestbook-ui-6595f948db from 1 to 5
  Normal  ScalingReplicaSet  52s    deployment-controller  Scaled down replica set guestbook-ui-6595f948db from 5 to 1
```

## Wait for sync to complete

If you need to block until an application reaches Synced (and optionally Healthy), use:

```bash theme={null}
argocd app wait web-frontend --sync
```

Example output when the app is Synced and Healthy:

```console theme={null}
Name:                argocd/web-frontend
Project:             default
Server:              https://kubernetes.default.svc
Namespace:           applications
URL:                 http://localhost:30080/applications/web-frontend
Source:
  - Repo:             https://github.com/argoproj/argocd-example-apps.git
    Path:             guestbook
SyncWindow:          Sync Allowed
Sync Policy:         Automated (Prune)
Sync Status:         Synced to (723b86e)
Health Status:       Healthy

GROUP   KIND        NAMESPACE     NAME          STATUS  HEALTH   HOOK  MESSAGE
apps    Deployment  applications  guestbook-ui  Synced  Healthy       deployment.apps/guestbook-ui configured
apps    Service     applications  guestbook-ui  Synced  Healthy
```

## Common Argo CD CLI commands

| Task | Command example |
| - | - |
| Login to Argo CD | `argocd login localhost:30080 --username admin --password <PASSWORD> --insecure` |
| Create app | `argocd app create web-frontend --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace applications` |
| Get app status | `argocd app get web-frontend` |
| Sync app | `argocd app sync web-frontend` |
| Set automated sync | `argocd app set web-frontend --sync-policy automated` |
| Enable self-heal | `argocd app set web-frontend --self-heal` |
| Enable auto-prune | `argocd app set web-frontend --auto-prune` |
| Wait for sync | `argocd app wait web-frontend --sync` |

## References and further reading

* Argo CD official docs: [https://argo-cd.readthedocs.io/](https://argo-cd.readthedocs.io/)
* GitOps with Argo CD: [https://argo-cd.readthedocs.io/en/stable/getting\_started/](https://argo-cd.readthedocs.io/en/stable/getting_started/)
* Kubernetes docs: [https://kubernetes.io/docs/](https://kubernetes.io/docs/)

## Conclusion

Everything you can manage in the Argo CD UI is also available via the CLI: creating applications, syncing, enabling automated sync/self-heal/auto-prune, and monitoring application/resource status. The CLI provides the same control and visibility in a scriptable form, making it ideal for automation and CI/CD pipelines.

> **[Watch Video](https://learn.kodekloud.com/user/courses/prep-course-certified-cloud-native-platform-engineer-cnpe/module/dff5382b-dbe7-4cac-bd2b-d5a47028945e/lesson/96c7a748-3848-424d-9933-e90d4f8cd5dd)**

> **[Practice Lab](https://learn.kodekloud.com/user/courses/prep-course-certified-cloud-native-platform-engineer-cnpe/module/dff5382b-dbe7-4cac-bd2b-d5a47028945e/lesson/efa3002a-4ec7-4dde-abad-486ec7e5bcd9)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.