Skip to main content
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),
  • Enables add-ons (metrics-server, ingress, dashboard),
  • Deploys an nginx demo application and prints access information.
A presentation slide titled "Creating Kubernetes Clusters with Claude" with a large "Demo" label on a dark curved background. A small "© Copyright KodeKloud" appears in the bottom corner.
Estimated time: ~15–30 minutes (depending on downloads and VM resources)
Difficulty: Intermediate
Environment and prerequisites
RequirementNotes / Recommendation
VM (Linux — Ubuntu) with sudo accessLocal VM, EC2, GCP, Azure, etc.
RAM & CPURecommended: 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 accessRequired to download packages and container images
Shell accessAbility to run curl and install packages with sudo
1 — Install Claude Code on the VM Install the Claude Code CLI on the machine where you plan to run this automation. For the KodeKloud course use the provided installer:
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:
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:
* Welcome to Claude Code!

/help for help, /status for your current setup

cwd: /home/ubuntu

Tips for getting started:

Run /init to create a CLAUDE.md file with instructions for Claude
Use Claude to help with file analysis, editing, bash commands and git
Be as specific as you would with another engineer for the best results

Note: You have launched claude in your home directory. For the best
experience, 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 script Save 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.
#!/usr/bin/env bash
set -euo pipefail

# Configuration
PROFILE_NAME="demo"
NODES=3
CPU=2
MEM=4096

# Determine non-root user (when run with sudo)
TARGET_USER="${SUDO_USER:-$USER}"

# Update package list
sudo apt-get update -y

# Install prerequisites
sudo apt-get install -y ca-certificates curl gnupg apt-transport-https \
    conntrack socat ebtables ethtool

# Configure kernel modules and sysctls
sudo modprobe br_netfilter || true
echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee /etc/sysctl.d/99-k8s.conf >/dev/null
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.d/99-k8s.conf >/dev/null
sudo 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" || true
fi

# 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 kubectl
fi

# 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 minikube
fi

# Start Minikube profile if it doesn't exist
if ! 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 context
if ! minikube -p "$PROFILE_NAME" addons list | grep -q "metrics-server.*enabled"; then
    newgrp docker <<'EOFF'
minikube -p "$PROFILE_NAME" addons enable metrics-server || true
minikube -p "$PROFILE_NAME" addons enable ingress || true
minikube -p "$PROFILE_NAME" addons enable dashboard || true
EOFF
fi

# Deploy demo app if not present
if ! kubectl get deploy hello >/dev/null 2>&1; then
    kubectl create deployment hello --image=nginx --port=80
    kubectl expose deployment hello --type=NodePort --port=80
fi

# Final status output
echo "=== Nodes ==="
kubectl get nodes -o wide || true

echo
echo "=== Services ==="
kubectl get svc -o wide || true

echo
echo "=== Demo URL(s) ==="
minikube -p "$PROFILE_NAME" service hello --url || true

echo
echo "Fallback (port-forward from this VM):"
echo "  kubectl port-forward deploy/hello 8080:80"
echo "Then curl http://localhost:8080"
Make the script executable and run it:
chmod +x /tmp/minikube-demo.sh
/tmp/minikube-demo.sh
4 — Handling Docker group and add-ons When 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:
# Ensure the current shell has docker group privileges, then:
newgrp docker
minikube -p demo addons enable metrics-server
minikube -p demo addons enable ingress
minikube -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:
kubectl port-forward deploy/hello 8080:80 &
PF_PID=$!
sleep 2
curl -s http://localhost:8080 | head -n 5
kill "$PF_PID" 2>/dev/null || true
Alternatively, use the Minikube-provided service URL printed by the script:
minikube -p demo service hello --url
6 — Expected result summary After the script runs successfully you should see:
ComponentWhat to expect
Prereqsca-certificates, curl, gnupg, apt-transport-https, conntrack, socat, ebtables, ethtool installed
Sysctlsnet.bridge.bridge-nf-call-iptables=1 and net.ipv4.ip_forward=1 applied
DockerInstalled, enabled, and user added to docker group
kubectlInstalled from the official pkgs.k8s.io repository
MinikubeInstalled and a 3-node Minikube profile named “demo” started (Docker driver)
Add-onsmetrics-server, ingress, dashboard enabled (if permissions allow)
Demo app”hello” nginx Deployment created and exposed as a NodePort service
AccessDemo URL(s) printed and a port-forward fallback provided
Example verification console snippets you may see:
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Handling connection for 8080
and
=== Nodes ===
NAME                 STATUS   ROLES    AGE   VERSION
demo-m01             Ready    control-plane   2m    v1.33.1
demo-m02             Ready    <none>          2m    v1.33.1
demo-m03             Ready    <none>          2m    v1.33.1

=== Services ===
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
hello        NodePort    10.96.0.123      <none>        80:31902/TCP   1m

=== Demo URL(s) ===
http://192.168.49.2:31902
Notes and tips
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.
Links and references 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.

Watch Video