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

# ARGOCD CLI

# Argo CD CLI Basics – From Zero to Managing Apps

This document assumes:

* Argo CD is already installed in the cluster
* You have `kubectl` access
* You are using the **Argo CD CLI (`argocd`)**

***

## 1. Install Argo CD CLI

### macOS

```bash theme={null}
brew install argocd
```

### Linux

```bash theme={null}
curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod +x argocd
sudo mv argocd /usr/local/bin/
```

Verify:

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

***

## 2. Access Argo CD Server

Most clusters expose Argo CD as **ClusterIP**, so you must port-forward.

```bash theme={null}
kubectl -n argocd port-forward svc/argocd-server 8080:443
```

Argo CD is now reachable at:

```
https://localhost:8080
```

***

## 3. Get Initial Admin Password

```bash theme={null}
kubectl -n argocd get secret argocd-initial-admin-secret \
  -o jsonpath="{.data.password}" | base64 -d
```

Save it. You’ll need it once.

***

## 4. Login Using Argo CD CLI

```bash theme={null}
argocd login localhost:8080 \
  --username admin \
  --password <PASSWORD> \
  --insecure
```

Why `--insecure`?

* Argo uses a self-signed cert by default.
* Without it, CLI login fails.

Verify login:

```bash theme={null}
argocd account get-user-info
```

If this fails, **nothing else will work**. Stop here and fix login first.

***

## 5. Repository Management (Git)

### List repositories

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

***

### Add a Git repository (HTTPS)

```bash theme={null}
argocd repo add https://bitbucket.org/org/repo.git \
  --username <user> \
  --password <app-password>
```

⚠️ Never use real account password. Always use **app password / token**.

***

### Add a Git repository (SSH – recommended)

```bash theme={null}
argocd repo add git@bitbucket.org:org/repo.git \
  --ssh-private-key-path ~/.ssh/argocd_id_rsa
```

Requirements:

* Private key has **no passphrase** (or provide one)
* Public key added to **repo access keys** in Git provider
* Repo URL must be SSH (`git@...`)

***

### Remove a repository

```bash theme={null}
argocd repo rm git@bitbucket.org:org/repo.git
```

***

### Get repository details

```bash theme={null}
argocd repo get git@bitbucket.org:org/repo.git
```

Use this when “Connected” lies to you.

***

## 6. Application Basics

An **Application** = Git repo + path + cluster + namespace.

***

### List applications

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

***

### Create an application (imperative)

```bash theme={null}
argocd app create my-app \
  --repo git@bitbucket.org:org/repo.git \
  --path manifests \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace default \
  --sync-policy automated
```

Key flags explained:

* `--repo` → Git repository
* `--path` → Folder inside repo
* `--dest-server` → Target cluster
* `--dest-namespace` → Target namespace
* `--sync-policy automated` → Auto-sync (optional)

***

### Create app without auto-sync (manual control)

```bash theme={null}
argocd app create my-app \
  --repo git@bitbucket.org:org/repo.git \
  --path manifests \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace default
```

***

## 7. Syncing Applications

### Manual sync

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

***

### Refresh app state (re-fetch Git)

```bash theme={null}
argocd app refresh my-app
```

This is **mandatory** after:

* Repo credential changes
* Branch/tag changes
* Repo-server restarts

***

### Force sync (dangerous but sometimes needed)

```bash theme={null}
argocd app sync my-app --force
```

This will:

* Recreate resources
* Overwrite drift
* Potentially cause downtime

Use sparingly.

***

## 8. Application Inspection & Debugging

### Get app details

```bash theme={null}
argocd app get my-app
```

***

### View app history

```bash theme={null}
argocd app history my-app
```

***

### Rollback to a previous revision

```bash theme={null}
argocd app rollback my-app <REVISION_ID>
```

***

### Delete an application

```bash theme={null}
argocd app delete my-app
```

Add `--cascade` to delete cluster resources too:

```bash theme={null}
argocd app delete my-app --cascade
```

***

## 9. Cluster Management

### List clusters known to Argo CD

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

***

### Add current cluster

```bash theme={null}
argocd cluster add <kubectl-context>
```

Example:

```bash theme={null}
argocd cluster add arn:aws:eks:ap-south-1:123456789:cluster/prod
```

***

## 10. Common Operational Commands

### Restart repo-server (Git issues)

```bash theme={null}
kubectl rollout restart deployment argocd-repo-server -n argocd
```

***

### Restart application controller

```bash theme={null}
kubectl rollout restart statefulset argocd-application-controller -n argocd
```

***

### Check Argo CD components

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

***

## 11. Mental Model (Important)

* Argo CD **does not continuously validate repo auth**
* “Connected” ≠ “Can fetch”
* `git fetch` failure = broken auth
* SSH issues are **almost always key placement or repo URL mistakes**
* CLI errors > UI indicators

***

## Strong Opinion (earned from pain)

If this is a real environment:

* ✅ Use **SSH deploy keys**
* ✅ Use **service accounts**
* ❌ Avoid personal credentials
* ❌ Avoid trusting UI status

***

If you want next:

* ApplicationSet CLI usage
* Multi-env repo structure (dev/stage/prod)
* How Argo CD actually stores repo credentials (secrets)
* Hardening Argo CD for production

Say the word and I’ll go straight into it.
