-
Notifications
You must be signed in to change notification settings - Fork 3.5k
minikube installation shell script #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA new Bash script is introduced that automates the complete Minikube setup process on Ubuntu systems, including package management, Docker and kubectl installation, cluster initialization, and verification of the deployment environment. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant System as Ubuntu System
participant Docker
participant Minikube
participant kubectl
participant K8sCluster as Kubernetes Cluster
User->>System: Execute install_minikube.sh
System->>System: Update package manager
System->>System: Install curl, wget, transport packages
System->>Docker: Install Docker daemon
Docker->>System: Enable and start Docker service
System->>System: Add user to docker group
System->>Minikube: Download & install Minikube<br/>(arch-specific binary)
System->>kubectl: Download & install kubectl<br/>(version from K8s release)
Minikube->>Docker: Initialize cluster with<br/>Docker driver
Docker->>K8sCluster: Provision Kubernetes nodes
System->>Minikube: Verify Minikube status
System->>K8sCluster: Verify Kubernetes nodes
K8sCluster-->>User: ✓ Setup complete
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
theyashbalani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emojis removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
install_minikube.sh (3)
1-3: Enhance error handling withset -o pipefail.While
set -eexits on command failures, it doesn't catch errors within pipelines. Addingset -o pipefailensures that errors in piped commands (e.g.,curl -Ls | grep) are also caught, making the script more robust.#!/bin/bash set -e +set -o pipefail
42-62: Extract architecture detection into a reusable function.The architecture detection logic (lines 45–53) is duplicated identically in the kubectl installation section (lines 71–81). Extract this into a function to reduce duplication and improve maintainability.
# Add near the top of the script, after set -e get_arch() { ARCH=$(uname -m) if [ "$ARCH" = "x86_64" ]; then echo "amd64" elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then echo "arm64" else echo "Unsupported architecture: $ARCH" >&2 exit 1 fi } # Then simplify both sections: # ARCH=$(get_arch) # URL="https://storage.googleapis.com/minikube/releases/latest/minikube-linux-${ARCH}"
101-113: Consider adding status validation instead of just printing output.The status checks (lines 105, 108) display information but don't validate that Minikube is actually ready for use. Consider adding explicit checks:
echo "Checking Minikube status..." minikube status - echo "Kubernetes nodes:" - kubectl get nodes + echo "Kubernetes nodes:" + if ! kubectl get nodes; then + echo "Error: Kubernetes nodes not accessible" + exit 1 + fi + + # Optional: Wait for nodes to be in Ready state + echo "Waiting for nodes to be ready..." + kubectl wait --for=condition=Ready nodes --all --timeout=300s || true
| sudo usermod -aG docker "$USER" | ||
| echo "Please log out and log back in OR run: newgrp docker" | ||
| else | ||
| echo "Docker is already installed." | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docker group membership won't be active in current session.
After installing Docker and adding the user to the docker group (line 32), the group membership won't take effect in the current shell session. When the script reaches line 96 (minikube start --driver=docker), it will fail with permission denied because the user hasn't yet acquired the new group permissions.
Either spawn a new group session after Docker setup, or ensure the user runs the next commands after logging out/in:
echo "Adding current user to Docker group..."
sudo usermod -aG docker "$USER"
- echo "Please log out and log back in OR run: newgrp docker"
+
+ # Apply group membership to current session
+ newgrp docker <<EOF
+ # Continue execution in new group context
+EOFAlternatively, defer Minikube cluster startup to a follow-up script or document that users must exit and re-enter their shell before proceeding.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In install_minikube.sh around lines 32 to 36, after running sudo usermod -aG
docker "$USER" the new docker group membership will not be active in the current
shell so subsequent minikube start --driver=docker (later in the script) can
fail with permission denied; update the script to either (a) invoke newgrp
docker (or exec sg docker "$SHELL" /bin/sh -c "…") immediately after adding the
user so the remainder of the script runs with the new group, or (b) stop/start
only the Docker-related setup and print a clear message that the user must log
out and log back in (or run newgrp docker) before running the minikube start
command or running a follow-up script that performs cluster startup; implement
one of these flows and ensure the script exits if the group change was not
applied to avoid proceeding to minikube start without proper permissions.
| if ! command -v kubectl &>/dev/null; then | ||
| echo "Installing kubectl (latest stable version)..." | ||
|
|
||
| ARCH=$(uname -m) | ||
| VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt) | ||
|
|
||
| if [ "$ARCH" = "x86_64" ]; then | ||
| curl -Lo kubectl "https://dl.k8s.io/release/${VERSION}/bin/linux/amd64/kubectl" | ||
| elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then | ||
| curl -Lo kubectl "https://dl.k8s.io/release/${VERSION}/bin/linux/arm64/kubectl" | ||
| else | ||
| echo "Unsupported architecture: $ARCH" | ||
| exit 1 | ||
| fi | ||
|
|
||
| chmod +x kubectl | ||
| sudo mv kubectl /usr/local/bin/kubectl | ||
|
|
||
| echo "kubectl installed successfully." | ||
| else | ||
| echo "kubectl is already installed." | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify VERSION variable contains valid data before using it.
Line 72 fetches the Kubernetes stable version, but if the curl request fails or the endpoint is unavailable, VERSION may be empty or malformed. This could cause the subsequent curl commands (lines 75, 77) to construct invalid URLs. Add explicit validation:
ARCH=$(uname -m)
VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt)
+
+ if [ -z "$VERSION" ]; then
+ echo "Error: Failed to fetch Kubernetes stable version"
+ exit 1
+ fi
+
+ # Trim any whitespace
+ VERSION=$(echo "$VERSION" | xargs)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if ! command -v kubectl &>/dev/null; then | |
| echo "Installing kubectl (latest stable version)..." | |
| ARCH=$(uname -m) | |
| VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt) | |
| if [ "$ARCH" = "x86_64" ]; then | |
| curl -Lo kubectl "https://dl.k8s.io/release/${VERSION}/bin/linux/amd64/kubectl" | |
| elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then | |
| curl -Lo kubectl "https://dl.k8s.io/release/${VERSION}/bin/linux/arm64/kubectl" | |
| else | |
| echo "Unsupported architecture: $ARCH" | |
| exit 1 | |
| fi | |
| chmod +x kubectl | |
| sudo mv kubectl /usr/local/bin/kubectl | |
| echo "kubectl installed successfully." | |
| else | |
| echo "kubectl is already installed." | |
| fi | |
| if ! command -v kubectl &>/dev/null; then | |
| echo "Installing kubectl (latest stable version)..." | |
| ARCH=$(uname -m) | |
| VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt) | |
| if [ -z "$VERSION" ]; then | |
| echo "Error: Failed to fetch Kubernetes stable version" | |
| exit 1 | |
| fi | |
| # Trim any whitespace | |
| VERSION=$(echo "$VERSION" | xargs) | |
| if [ "$ARCH" = "x86_64" ]; then | |
| curl -Lo kubectl "https://dl.k8s.io/release/${VERSION}/bin/linux/amd64/kubectl" | |
| elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then | |
| curl -Lo kubectl "https://dl.k8s.io/release/${VERSION}/bin/linux/arm64/kubectl" | |
| else | |
| echo "Unsupported architecture: $ARCH" | |
| exit 1 | |
| fi | |
| chmod +x kubectl | |
| sudo mv kubectl /usr/local/bin/kubectl | |
| echo "kubectl installed successfully." | |
| else | |
| echo "kubectl is already installed." | |
| fi |
🤖 Prompt for AI Agents
In install_minikube.sh around lines 68 to 89, the script uses VERSION from a
curl call without validating it; update the script to verify that VERSION is
non-empty and matches an expected Kubernetes release format before using it in
download URLs, e.g. check curl succeeded (non-zero exit) and that VERSION is not
empty and optionally matches a regex like ^v[0-9]+\.[0-9]+\.[0-9]+$, and if
validation fails either retry the request a couple times or print a clear error
and exit with non-zero status so invalid URLs are never constructed.
| echo "Starting Minikube cluster using Docker driver..." | ||
| minikube start --driver=docker --vm=true | ||
|
|
||
| echo "Minikube cluster started successfully!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
minikube Docker driver --vm=true flag documentation
💡 Result:
The --vm=true flag tells minikube to create/run the cluster inside a VM (use a VM driver) instead of using the Docker/Podman driver. It's commonly used on macOS/Windows or whenever you need a VM-backed cluster (for example to enable ingress or run eBPF tools). If a profile already uses the docker driver, the saved profile may override --vm=true — you may need to stop/delete the profile and restart with a VM driver (or explicitly pass --driver=<hyperkit|virtualbox|hyperv>). [1][2][3]
Sources:
- minikube eBPF tutorial (example using minikube start --vm=true). [1]
- minikube Docker-desktop-replacement / how-to (example using --container-runtime=docker --vm=true). [2]
- Community Q&A explaining that existing profile can override --vm=true and recommending minikube stop && minikube delete then minikube start --vm=true --driver=hyperkit. [3]
Remove the --vm=true flag—it conflicts with the Docker driver.
Line 96 uses minikube start --driver=docker --vm=true, but these flags are contradictory. The --vm=true flag instructs minikube to run the cluster inside a VM using a VM driver (hyperkit, virtualbox, hyperv), while --driver=docker runs containers directly in Docker without a VM. When both are specified, an existing docker driver profile may override the --vm=true flag, leading to unexpected behavior. Use minikube start --driver=docker alone.
🤖 Prompt for AI Agents
In install_minikube.sh around lines 95 to 98 the minikube start call uses
conflicting flags (`--driver=docker --vm=true`); remove the `--vm=true` flag and
invoke minikube start with only `--driver=docker` so the Docker driver is used
consistently and no VM-specific option conflicts with it.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.