argocd-nix-lab/LAB_ARGOCD_CLI.md
2025-12-27 16:27:03 +02:00

2.4 KiB

Lab: Mastering the ArgoCD CLI

This lab will guide you through managing your GitOps workflow using the argocd command-line interface, which is faster and often more scriptable than the UI.

Prerequisites

Ensure you have run make setup and your cluster is running.

Step 1: Establish Connection

  1. Port Forward (if not already running): Open a separate terminal and run:

    kubectl port-forward svc/argocd-server -n argocd 8080:443
    
  2. Get the Admin Password:

    kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
    
  3. Login with CLI:

    # Accept the self-signed certificate warning with 'y'
    argocd login localhost:8080 --username admin --password <YOUR_PASSWORD_ABOVE>
    

Step 2: Inspecting Applications

  1. List all apps:

    argocd app list
    

    Observe the guestbook app status (Synced/Healthy).

  2. Get detailed info:

    argocd app get guestbook
    

    This shows the "Service" and "Deployment" resources managed by this app.

  3. Check Sync History:

    argocd app history guestbook
    

Step 3: Triggering Actions

  1. Force a Refresh: Sometimes ArgoCD doesn't pick up git changes immediately (default is 3m poll). Force it:

    argocd app get guestbook --refresh
    
  2. Manual Sync: If an app is "OutOfSync", you can trigger it manually:

    argocd app sync guestbook
    

Step 4: Imperative Deployment (The "Quick & Dirty" way)

While we prefer declarative YAML (application.yaml), sometimes you need to test something quickly.

  1. Deploy the "Sock Shop" demo app:

    argocd app create sock-shop \
      --repo https://github.com/argoproj/argocd-example-apps.git \
      --path sock-shop \
      --dest-server https://kubernetes.default.svc \
      --dest-namespace default
    
  2. Sync it (Deploy it): Newly created apps are usually "OutOfSync" and "Missing" initially.

    argocd app sync sock-shop
    
  3. Verify:

    argocd app list
    kubectl get pods -n default
    

Step 5: Clean Up

  1. Delete the imperative app:
    argocd app delete sock-shop --cascade
    
    Confirm with y. --cascade ensures k8s resources (deployments/services) are deleted too.