Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions install_minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash

set -e

echo "Starting Minikube Installation on Ubuntu..."

# ----------------------------
# 1. Update System Packages
# ----------------------------
echo "Updating apt package list..."
sudo apt update -y


# ----------------------------
# 2. Install Required Packages
# ----------------------------
echo "Installing curl, wget, apt-transport-https..."
sudo apt install -y curl wget apt-transport-https


# ----------------------------
# 3. Install Docker (Minikube driver)
# ----------------------------
if ! command -v docker &>/dev/null; then
echo "Installing Docker..."
sudo apt install -y docker.io

echo "Enabling and starting Docker..."
sudo systemctl enable --now docker

echo "Adding current user to Docker group..."
sudo usermod -aG docker "$USER"
echo "Please log out and log back in OR run: newgrp docker"
else
echo "Docker is already installed."
fi
Comment on lines +32 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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
+EOF

Alternatively, 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.



# ----------------------------
# 4. Install Minikube (based on architecture)
# ----------------------------
if ! command -v minikube &>/dev/null; then
echo "Installing Minikube..."

ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
URL="https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
URL="https://storage.googleapis.com/minikube/releases/latest/minikube-linux-arm64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi

curl -Lo minikube "$URL"
chmod +x minikube
sudo mv minikube /usr/local/bin/minikube

echo "Minikube installed successfully."
else
echo "Minikube is already installed."
fi


# ----------------------------
# 5. Install kubectl (based on architecture)
# ----------------------------
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
Comment on lines +68 to +89
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.



# ----------------------------
# 6. Start Minikube
# ----------------------------
echo "Starting Minikube cluster using Docker driver..."
minikube start --driver=docker --vm=true

echo "Minikube cluster started successfully!"
Comment on lines +95 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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.



# ----------------------------
# 7. Show Cluster Status
# ----------------------------
echo "Checking Minikube status..."
minikube status

echo "Kubernetes nodes:"
kubectl get nodes


echo "Installation complete! You can now use Minikube + kubectl."
echo "To stop Minikube: minikube stop"
echo "To delete cluster: minikube delete"