Skip to main content
In this lesson we’ll create a reproducible Kubernetes cluster on a Linux VM using Claude Code. The example demonstrates how Claude Code can generate and execute an idempotent Bash script to:
  • install prerequisites,
  • install Docker, kubectl and Minikube,
  • start a multi-node Minikube cluster,
  • enable useful addons,
  • deploy a demo nginx app exposed as a NodePort service,
  • and provide convenient access details and fallbacks.
A presentation slide reading "Creating Kubernetes Clusters with Claude" on the left and a large "Demo" label inside a dark blue curved shape on the right. A small "© Copyright KodeKloud" appears in the bottom-left.
Overview
  • This guide shows how to install Claude Code on an Ubuntu VM, sign in, and ask it to create a Minikube-based Kubernetes cluster.
  • Claude Code can execute Bash commands on the machine where it’s installed. The example uses a VM (for example, Amazon EC2), but any Linux VM (local or cloud) works.
  • The final result is a 3-node Minikube cluster named demo, with an nginx “hello” Deployment exposed through a NodePort.
For a 3-node Minikube cluster sized with 2 CPUs and 4GB memory per node you will need a VM with enough total RAM and CPU (roughly 12GB RAM + host overhead and at least 6 CPUs). If you only have a single smaller VM, reduce node counts and/or memory values.
Quick configuration summary Installing and signing in to Claude Code
  1. Install Claude Code on the VM (example):
  1. Start Claude Code:
  1. Follow the interactive sign-in flow. If the installer prints an OAuth URL, open it in a browser and paste the code/token back into the Claude prompt. Example installer prompt (truncated):
After completing browser authorization you should see a small interactive prompt similar to:
Preparing the task: the prompt we gave Claude Code We asked Claude Code to run a non-interactive plan on the Ubuntu VM to:
  • Install prerequisites (ca-certificates, curl, gnupg, apt-transport-https, conntrack, socat, ebtables, ethtool) and apply sysctls for bridge and IP forwarding.
  • Install Docker (docker.io), enable/start it, and add the current user to the docker group.
  • Install kubectl from the official APT repo.
  • Install Minikube (latest Linux binary).
  • Start a 3-node Minikube cluster named demo using the Docker driver with --cpus=2 and --memory=4096 per node.
  • Enable addons: metrics-server, ingress, dashboard.
  • Deploy a hello nginx Deployment and expose it as a NodePort service.
  • Print nodes, services, and a reachable URL via minikube -p demo service hello --url. Provide a port-forward fallback command.
  • Make actions idempotent and handle docker-group membership changes by attempting a newgrp docker block if required.
Human-readable version of the instruction (as supplied to Claude Code):
The final automated script Claude Code generated and executed a script at /tmp/minikube-demo.sh. Below is a cleaned, idempotent script (the same, improved and consistent version used in the lesson/article). Save this script as /tmp/minikube-demo.sh if you want to run it yourself.
How Claude executed and validated the setup
  • Claude created the script at /tmp/minikube-demo.sh, made it executable, and executed it non-interactively.
  • When docker-group membership changes blocked some actions, Claude used newgrp docker to run the relevant Minikube commands in the correct group context.
  • Claude validated the demo application by performing a kubectl port-forward and running a curl against the forwarded port to confirm the nginx default page responded.
Example verification output (representative, truncated)
Notes and troubleshooting tips
  • Docker group: after adding your user to the docker group you may need to log out/in, restart the shell, or run newgrp docker for group membership to take effect.
  • Resource constraints: Minikube multi-node clusters using the Docker driver create multiple containers on the host; ensure sufficient disk, CPU, and memory. If resources are limited, reduce NODES, CPU, or MEM.
  • Addon image pulls: if an addon fails to enable due to image pull/network issues, verify network connectivity and retry:
    • minikube -p demo addons enable <addon>
  • If kubectl commands fail due to context, ensure Minikube’s kubeconfig is active for the profile:
    • minikube -p demo kubectl -- get nodes
Conclusion Using Claude Code on a VM you control streamlines creating reproducible local Kubernetes environments. By providing a concise plan and desired parameters (profile name, node count, CPU/memory), Claude Code can produce an idempotent script, run it, and validate the running cluster—saving time and reducing manual errors. If you want to reuse this example, save the script above to /tmp/minikube-demo.sh and adjust PROFILE_NAME, node count, CPU, and memory values to match your available resources. Links and References

Watch Video