> ## 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 Create and Sync Application using CLI

> Guide to creating and syncing an Argo CD application entirely via the argocd CLI, including installation, login, app creation, namespace setup, synchronization, and troubleshooting

In this guide you'll learn how to create an Argo CD application entirely from the command line and synchronize it to a Kubernetes cluster using the argocd CLI. Follow these steps:

* Install the argocd CLI
* Authenticate (log in) to your Argo CD server
* List existing applications
* Create a new application with the CLI
* Create the target namespace (if necessary)
* Synchronize the application and verify status

For background reading, see the Argo CD documentation: [Argo CD Docs](https://argo-cd.readthedocs.io/) and the Kubernetes docs: [Kubernetes Concepts](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/).

## 1. Install the argocd CLI

Choose the installation method that matches your OS. The following table summarizes common options.

|                       Platform | Installation                                |
| -----------------------------: | ------------------------------------------- |
|                     Arch Linux | `pacman -S argocd`                          |
|               macOS (Homebrew) | `brew install argocd`                       |
| Linux (direct download, amd64) | Download and install binary (example below) |
|               Specific release | Download the desired release from GitHub    |

Example direct download (Linux amd64):

```bash theme={null}
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
```

To install a specific release, replace `latest` with the release tag:

```bash theme={null}
VERSION=<TAG> # pick a release tag from https://github.com/argoproj/argo-cd/releases
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
```

Verify the client version:

```bash theme={null}
argocd version
```

Example client-only output:

```text theme={null}
argocd: v3.1.5+cfed49
BuildDate: 2025-09-10T16:01:20Z
GitCommit: cfed4910542c359f18537a6668d4671abd3813b
GitTreeState: clean
GoVersion: go1.24.6
Compiler: gc
Platform: linux/amd64
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/v7HW2PPNQOGxY8Ve/images/Prep-Course-Certified-Argo-Project-Associate-CAPA/ArgoCD/Demo-Create-and-Sync-Application-using-CLI/dark-vscode-argo-cd-terminal.jpg?fit=max&auto=format&n=v7HW2PPNQOGxY8Ve&q=85&s=1186d500200f7925ca25da222bc1dc7f" alt="A dark-themed Visual Studio Code window with the integrated terminal displaying the Argo CD CLI help output (a list of available commands and flags). The Explorer sidebar is visible on the left and a faint Argo CD/VS Code logo appears in the editor area." width="1920" height="1080" data-path="images/Prep-Course-Certified-Argo-Project-Associate-CAPA/ArgoCD/Demo-Create-and-Sync-Application-using-CLI/dark-vscode-argo-cd-terminal.jpg" />
</Frame>

If the CLI cannot reach the Argo CD API server, commands that contact the server (e.g., `argocd app list`) will return a connection error. You must log in before managing applications.

## 2. Log in to the Argo CD server

First, try listing applications. If you're not logged in or the CLI can't reach the server, this will fail:

```bash theme={null}
argocd app list
```

If you get an error such as "Failed to establish connection ... connection refused", confirm the argocd-server service and its NodePort or load balancer address.

Find the argocd server service in the `argocd` namespace:

```bash theme={null}
# If you don't have the alias `k`, use kubectl
kubectl -n argocd get svc
```

Note the NodePort (example: `31148`) or external IP. Then log in with the CLI, replacing `<NODEPORT>` with the correct host:port (e.g., `localhost:31148`):

```bash theme={null}
argocd login localhost:31148
```

The login flow may prompt:

* A TLS certificate verification warning (if the server uses a self-signed cert)
* Username (commonly `admin` unless changed)
* Password

<Callout icon="warning" color="#FF6B6B">
  If the server uses a self-signed certificate, argocd will warn that the certificate is signed by an unknown authority. You can proceed insecurely by answering `y` to the prompt, but for production environments configure TLS correctly to avoid security risks.
</Callout>

On successful login you should see:

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

Now retry:

```bash theme={null}
argocd app list
```

Example output for one existing app:

```text theme={null}
NAME                      CLUSTER                         NAMESPACE          PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                              PATH       TARGET
argocd/highway-animation  https://kubernetes.default.svc  highway-animation  default  Synced  Healthy  Manual      <none>      http://host.docker.internal:5000/kk-org/capa-demos  ./vanilla  HEAD
```

## 3. Create a new application using the CLI

Create a new application (`app-2`) that points to the same repository and path as the existing app but targets a different namespace (`app-2`):

```bash theme={null}
argocd app create app-2 \
  --repo http://host.docker.internal:5000/kk-org/capa-demos \
  --path ./vanilla \
  --dest-namespace app-2 \
  --dest-server https://kubernetes.default.svc
```

Expected response:

```text theme={null}
application 'app-2' created
```

List applications again:

```bash theme={null}
argocd app list
```

Because the repository path is shared with another application, Argo CD may report shared resources and mark the new app as OutOfSync. Example output:

```text theme={null}
NAME                       CLUSTER                         NAMESPACE  PROJECT  STATUS     HEALTH   SYNCPOLICY   CONDITIONS                      REPO                                              PATH
argocd/app-2               https://kubernetes.default.svc  app-2      default  OutOfSync  Healthy  Manual       SharedResourceWarning(2)         http://host.docker.internal:5000/kk-org/capa-demos  ./vanilla
argocd/highway-animation   https://kubernetes.default.svc  highway-animation  default  Synced  Healthy  Manual   <none>                       http://host.docker.internal:5000/kk-org/capa-demos  ./vanilla  HEAD
```

## 4. Create the destination namespace (if needed)

If the destination namespace `app-2` does not exist, create it with kubectl:

```bash theme={null}
kubectl create ns app-2
# namespace/app-2 created
```

## 5. Synchronize the application

Sync the newly created application to apply the manifests to the cluster:

```bash theme={null}
argocd app sync app-2
```

During sync the CLI prints resource-level events and a summary. Example output:

```text theme={null}
TIMESTAMP                           GROUP   KIND        NAMESPACE  NAME                          STATUS     HEALTH    HOOK  MESSAGE
2025-10-23T10:32:26+00:00           v1      Service     app-2      highway-animation-service      OutOfSync  Healthy
2025-10-23T10:32:26+00:00           apps    Deployment  app-2      highway-animation              OutOfSync  Healthy
2025-10-23T10:32:27+00:00           v1      Service     app-2      highway-animation-service      Synced     Healthy   service/highway-animation-service configured
2025-10-23T10:32:28+00:00           apps    Deployment  app-2      highway-animation              Synced     Healthy   deployment.apps/highway-animation configured

Name:        argocd/app-2
Project:     default
Server:      https://kubernetes.default.svc
Namespace:   app-2
URL:         https://localhost:31148/applications/app-2
Source:
- Repo: http://host.docker.internal:5000/kk-org/capa-demos
  Path: ./vanilla
SyncWindow:  Sync Allowed
Sync Policy: Manual
Sync Status: Synced to (0c48696)
Health Status: Healthy
```

After the sync completes the application should appear as Synced / Healthy. Verify via the UI or with:

```bash theme={null}
argocd app list
```

## Troubleshooting and best practices

* Use unique resource names and namespaces when multiple Argo CD applications reference the same repository to avoid SharedResourceWarning.
* Prefer overlays, separate paths, or separate repositories when deploying distinct environments.
* For production, configure proper TLS certificates rather than accepting self-signed certificates.

<Callout icon="lightbulb" color="#1CB2FE">
  If multiple Argo CD applications point to the same manifests and overlap resources (same names/namespaces), Argo CD raises SharedResourceWarning. Avoid conflicts by using distinct repository paths, kustomize overlays, or separate namespaces and repositories.
</Callout>

This completes the demo for creating and synchronizing an Argo CD application using the CLI. For more examples and advanced workflows, see the [Argo CD CLI reference](https://argo-cd.readthedocs.io/en/stable/cli_operations/).

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-argo-project-associate-capa/module/9facbd04-7a3f-4200-9d6e-53936e93d875/lesson/ea24d846-8c67-457a-88d8-26a0873c94c7" />
</CardGroup>
