Demonstrates using Claude Code to generate and run an idempotent Bash script that installs prerequisites and launches a multi-node Minikube Kubernetes cluster with a demo nginx app
In this lesson you’ll see how a single detailed prompt to Claude Code For Beginners can generate and execute an idempotent Bash script that:
Installs prerequisites on an Ubuntu VM,
Configures kernel settings and systemd services,
Installs Docker, kubectl (from pkgs.k8s.io), and Minikube,
Starts a multi-node Minikube Kubernetes cluster (Docker driver),
Deploys an nginx demo application and prints access information.
Estimated time: ~15–30 minutes (depending on downloads and VM resources)
Difficulty: IntermediateEnvironment and prerequisites
Requirement
Notes / Recommendation
VM (Linux — Ubuntu) with sudo access
Local VM, EC2, GCP, Azure, etc.
RAM & CPU
Recommended: at least 8 GB RAM and 2+ vCPUs. If you plan a 3-node profile with 4 GB per node, increase host RAM accordingly.
Internet access
Required to download packages and container images
Shell access
Ability to run curl and install packages with sudo
1 — Install Claude Code on the VMInstall the Claude Code CLI on the machine where you plan to run this automation. For the KodeKloud course use the provided installer:
Copy
curl -sSL https://cloud.ai/install.sh | bash
After installing, launch the Claude Code CLI and follow the interactive sign-in. You may be asked to open a browser to paste an authorization code. Example abbreviated output:
Copy
Browser didn't open? Use the url below to sign in:https://claude.ai/oauth/authorize?code=...Logged in as [REDACTED_EMAIL]Login successful. Press Enter to continue...
Once signed in you’ll see the Claude Code prompt similar to:
Copy
* Welcome to Claude Code!/help for help, /status for your current setupcwd: /home/ubuntuTips for getting started:Run /init to create a CLAUDE.md file with instructions for ClaudeUse Claude to help with file analysis, editing, bash commands and gitBe as specific as you would with another engineer for the best resultsNote: You have launched claude in your home directory. For the bestexperience, launch it in a project directory instead.> Try "refactor <filepath>"? for shortcuts
2 — Provide a detailed prompt (the setup guide)We provided Claude Code a comprehensive prompt called “Minikube Kubernetes Demo Setup Guide” describing:
Prerequisites and system-level configuration (sysctls, modules),
Packages to install (Docker, kubectl, Minikube),
Cluster profile (name, node count, CPU, memory),
Add-ons to enable (metrics-server, ingress, dashboard),
Demo application to deploy (nginx “hello” deployment),
Verification steps and fallbacks (port-forward).
Claude Code used that prompt to generate a single idempotent Bash script that performs the entire setup. The script below is the consolidated output saved as /tmp/minikube-demo.sh.3 — The generated installation scriptSave the following to /tmp/minikube-demo.sh. The script is written to be idempotent: it checks for existing installs and skips re-installation where appropriate.
Copy
#!/usr/bin/env bashset -euo pipefail# ConfigurationPROFILE_NAME="demo"NODES=3CPU=2MEM=4096# Determine non-root user (when run with sudo)TARGET_USER="${SUDO_USER:-$USER}"# Update package listsudo apt-get update -y# Install prerequisitessudo apt-get install -y ca-certificates curl gnupg apt-transport-https \ conntrack socat ebtables ethtool# Configure kernel modules and sysctlssudo modprobe br_netfilter || trueecho "net.bridge.bridge-nf-call-iptables=1" | sudo tee /etc/sysctl.d/99-k8s.conf >/dev/nullecho "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.d/99-k8s.conf >/dev/nullsudo sysctl --system# Install Docker (idempotent)if ! command -v docker >/dev/null 2>&1; then sudo apt-get install -y docker.io sudo systemctl enable --now docker # Add the non-root user (or current user) to the docker group sudo usermod -aG docker "$TARGET_USER" || truefi# Install kubectl (using official packages)if ! command -v kubectl >/dev/null 2>&1; then sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.34/deb/Release.key \ | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.34/deb/ /" \ | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update -y sudo apt-get install -y kubectlfi# Install Minikube (idempotent)if ! command -v minikube >/dev/null 2>&1; then curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube /usr/local/bin/minikube rm -f minikubefi# Start Minikube profile if it doesn't existif ! minikube profile list -o=json | grep -q "\"Name\": \"$PROFILE_NAME\""; then # Start minikube using the docker driver minikube start -p "$PROFILE_NAME" --driver=docker --nodes="$NODES" --cpus="$CPU" --memory="$MEM"else echo "Minikube profile \"$PROFILE_NAME\" already exists; skipping start."fi# Enable addons (run under docker group context if necessary)# Some addon operations may require being in the docker group contextif ! minikube -p "$PROFILE_NAME" addons list | grep -q "metrics-server.*enabled"; then newgrp docker <<'EOFF'minikube -p "$PROFILE_NAME" addons enable metrics-server || trueminikube -p "$PROFILE_NAME" addons enable ingress || trueminikube -p "$PROFILE_NAME" addons enable dashboard || trueEOFFfi# Deploy demo app if not presentif ! kubectl get deploy hello >/dev/null 2>&1; then kubectl create deployment hello --image=nginx --port=80 kubectl expose deployment hello --type=NodePort --port=80fi# Final status outputecho "=== Nodes ==="kubectl get nodes -o wide || trueechoecho "=== Services ==="kubectl get svc -o wide || trueechoecho "=== Demo URL(s) ==="minikube -p "$PROFILE_NAME" service hello --url || trueechoecho "Fallback (port-forward from this VM):"echo " kubectl port-forward deploy/hello 8080:80"echo "Then curl http://localhost:8080"
4 — Handling Docker group and add-onsWhen the installer adds your user to the docker group, the membership may not take effect until you start a new login shell. The generated script attempts to enable add-ons inside a newgrp docker subshell to avoid permission errors. If an add-on fails due to permissions, re-run the add-on commands after obtaining docker group privileges:
Copy
# Ensure the current shell has docker group privileges, then:newgrp dockerminikube -p demo addons enable metrics-serverminikube -p demo addons enable ingressminikube -p demo addons enable dashboard
If you do not start a new shell or run newgrp docker, Minikube or addon commands may fail with permission errors. Log out and log back in, or use newgrp docker, before re-running addon commands.
5 — Test the demo application (port-forward)Quick port-forward test from the VM:
Running the full three-node demo on a single VM requires sufficient host resources. If you have limited RAM/CPU, reduce NODES or MEM in the script (for example, use 1 node or 2GB per node) to test locally. Also consider using fewer add-ons while troubleshooting.
Quick checklist (sanity checks)
Ensure the VM has enough RAM and CPUs for the configured node count.
Confirm internet connectivity for package and image downloads.
If kubectl or minikube fail unexpectedly, inspect logs and retry after ensuring docker group membership is active.
This lesson demonstrates how a single clear, structured prompt to Claude Code can produce an automated, idempotent script that reduces manual setup time for local Kubernetes testing with Minikube.