Bash script that automates the installation of Minikube on Ubuntu, including setting up Docker as the driver

Here’s a Bash script that automates the installation of Minikube on Ubuntu, including setting up Docker as the driver:

#!/bin/bash

# Exit script on any error
set -e

echo "Starting Minikube installation..."

# Step 1: Update and install dependencies
echo "Updating package list and installing dependencies..."
sudo apt update -y
sudo apt install -y curl apt-transport-https ca-certificates software-properties-common docker.io

# Step 2: Download Minikube binary
echo "Downloading Minikube binary..."
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

# Step 3: Make Minikube binary executable
echo "Making Minikube binary executable..."
chmod +x minikube-linux-amd64

# Step 4: Move Minikube binary to /usr/local/bin
echo "Moving Minikube binary to /usr/local/bin..."
sudo mv minikube-linux-amd64 /usr/local/bin/minikube

# Step 5: Start Docker
echo "Starting Docker service..."
sudo systemctl start docker
sudo systemctl enable docker

# Step 6: Add user to the Docker group
echo "Adding user to Docker group..."
sudo usermod -aG docker $USER
echo "Please log out and log back in to apply Docker group changes."

# Step 7: Start Minikube
echo "Starting Minikube with Docker driver..."
minikube start --driver=docker

# Step 8: Verify installation
echo "Verifying Minikube installation..."
minikube status

echo "Minikube installation completed successfully!"

How to Use This Script

  1. Save the script to a file, e.g., install_minikube.sh.
  2. Make the script executable: chmod +x install_minikube.sh
  3. Run the script: ./install_minikube.sh

After Running the Script

  • Log out and log back in to apply the Docker group changes.
  • Use minikube status to verify everything is running smoothly.
  • You can start the Kubernetes dashboard with: minikube dashboard