This commit is contained in:
Sergei Poljanski 2025-12-27 16:27:03 +02:00
commit 0e0297b89e
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
8 changed files with 258 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

91
LAB_ARGOCD_CLI.md Normal file
View file

@ -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 <YOUR_PASSWORD_ABOVE>
```
## 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.*

21
Makefile Normal file
View file

@ -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

33
README.md Normal file
View file

@ -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
```

View file

@ -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

22
argocd/application.yaml Normal file
View file

@ -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

27
flake.lock generated Normal file
View file

@ -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
}

30
flake.nix Normal file
View file

@ -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."
'';
};
};
}