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
-
Port Forward (if not already running): Open a separate terminal and run:
kubectl port-forward svc/argocd-server -n argocd 8080:443 -
Get the Admin Password:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo -
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
-
List all apps:
argocd app listObserve the
guestbookapp status (Synced/Healthy). -
Get detailed info:
argocd app get guestbookThis shows the "Service" and "Deployment" resources managed by this app.
-
Check Sync History:
argocd app history guestbook
Step 3: Triggering Actions
-
Force a Refresh: Sometimes ArgoCD doesn't pick up git changes immediately (default is 3m poll). Force it:
argocd app get guestbook --refresh -
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.
-
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 -
Sync it (Deploy it): Newly created apps are usually "OutOfSync" and "Missing" initially.
argocd app sync sock-shop -
Verify:
argocd app list kubectl get pods -n default
Step 5: Clean Up
- Delete the imperative app:
Confirm withargocd app delete sock-shop --cascadey.--cascadeensures k8s resources (deployments/services) are deleted too.