From 0e0297b89ed69d813639758235ae1ecaaf3974cc Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Sat, 27 Dec 2025 16:27:03 +0200 Subject: [PATCH] init --- .envrc | 1 + LAB_ARGOCD_CLI.md | 91 ++++++++++++++++++++++++++++++++++ Makefile | 21 ++++++++ README.md | 33 ++++++++++++ apps/guestbook/deployment.yaml | 33 ++++++++++++ argocd/application.yaml | 22 ++++++++ flake.lock | 27 ++++++++++ flake.nix | 30 +++++++++++ 8 files changed, 258 insertions(+) create mode 100644 .envrc create mode 100644 LAB_ARGOCD_CLI.md create mode 100644 Makefile create mode 100644 README.md create mode 100644 apps/guestbook/deployment.yaml create mode 100644 argocd/application.yaml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/LAB_ARGOCD_CLI.md b/LAB_ARGOCD_CLI.md new file mode 100644 index 0000000..5e6e1c0 --- /dev/null +++ b/LAB_ARGOCD_CLI.md @@ -0,0 +1,91 @@ +# 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: + ```bash + kubectl port-forward svc/argocd-server -n argocd 8080:443 + ``` + +2. **Get the Admin Password**: + ```bash + kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo + ``` + +3. **Login with CLI**: + ```bash + # Accept the self-signed certificate warning with 'y' + argocd login localhost:8080 --username admin --password + ``` + +## Step 2: Inspecting Applications + +1. **List all apps**: + ```bash + argocd app list + ``` + *Observe the `guestbook` app status (Synced/Healthy).* + +2. **Get detailed info**: + ```bash + argocd app get guestbook + ``` + *This shows the "Service" and "Deployment" resources managed by this app.* + +3. **Check Sync History**: + ```bash + 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: + ```bash + argocd app get guestbook --refresh + ``` + +2. **Manual Sync**: + If an app is "OutOfSync", you can trigger it manually: + ```bash + 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**: + ```bash + 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. + ```bash + argocd app sync sock-shop + ``` + +3. **Verify**: + ```bash + argocd app list + kubectl get pods -n default + ``` + +## Step 5: Clean Up + +1. **Delete the imperative app**: + ```bash + argocd app delete sock-shop --cascade + ``` + *Confirm with `y`. `--cascade` ensures k8s resources (deployments/services) are deleted too.* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0ee13ec --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +setup: + @echo "Creating Kind cluster..." + kind create cluster --name gitops-playground || true + @echo "Installing ArgoCD..." + kubectl create namespace argocd || true + kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml + @echo "Waiting for ArgoCD components (this may take a moment)..." + kubectl wait --for=condition=available deployment -l "app.kubernetes.io/name=argocd-server" -n argocd --timeout=300s + @echo "Applying Application Manifest..." + kubectl apply -f argocd/application.yaml + @echo "------------------------------------------------" + @echo "✅ Setup Complete!" + @echo "Access ArgoCD UI:" + @echo " 1. Port-forward: kubectl port-forward svc/argocd-server -n argocd 8080:443" + @echo " 2. Open: https://localhost:8080" + @echo " 3. Password:" + @echo "kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=\"{.data.password}\" | base64 -d; echo" + @echo " 4. Username: admin" + +clean: + kind delete cluster --name gitops-playground diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e1d93c --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# GitOps Playground (ArgoCD + Kind) + +## Prerequisites +- NixOS / Nix package manager +- Direnv (optional, but recommended) + +## Quick Start + +1. **Enter Environment:** + ```bash + direnv allow + # OR if not using direnv: + nix develop + ``` + +2. **Spin up Playground:** + ```bash + make setup + ``` + +3. **Access ArgoCD:** + - Run the port-forward command output by the make script. + - Login with `admin` and the printed password. + +4. **Experiment:** + - View the `guestbook` application in the UI. + - Modify `argocd/application.yaml` to point to a different repo or path. + - Run `k9s` to explore the cluster state. + +## Cleanup +```bash +make clean +``` diff --git a/apps/guestbook/deployment.yaml b/apps/guestbook/deployment.yaml new file mode 100644 index 0000000..87a697b --- /dev/null +++ b/apps/guestbook/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: guestbook-ui + namespace: guestbook +spec: + replicas: 1 + revisionHistoryLimit: 3 + selector: + matchLabels: + app: guestbook-ui + template: + metadata: + labels: + app: guestbook-ui + spec: + containers: + - image: gcr.io/heptio-images/ks-guestbook-demo:0.2 + name: guestbook-ui + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: guestbook-ui + namespace: guestbook +spec: + ports: + - port: 80 + targetPort: 80 + selector: + app: guestbook-ui diff --git a/argocd/application.yaml b/argocd/application.yaml new file mode 100644 index 0000000..02f5293 --- /dev/null +++ b/argocd/application.yaml @@ -0,0 +1,22 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: guestbook + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: default + source: + repoURL: https://github.com/argoproj/argocd-example-apps.git + targetRevision: HEAD + path: guestbook + destination: + server: https://kubernetes.default.svc + namespace: guestbook + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e5515b2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1766651565, + "narHash": "sha256-QEhk0eXgyIqTpJ/ehZKg9IKS7EtlWxF3N7DXy42zPfU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e2499d5539c16d0d173ba53552a4ff8547f4539", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..14d2c33 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + description = "GitOps Playground with ArgoCD and Kind"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.${system}.default = pkgs.mkShell { + buildInputs = with pkgs; [ + kind + kubectl + argocd + k9s + jq + ]; + + shellHook = '' + echo "🚀 GitOps Playground Environment Loaded" + echo "Tools available: kind, kubectl, argocd, k9s" + echo "Run 'make setup' to initialize the cluster." + ''; + }; + }; +}