Skip to content

Instantly share code, notes, and snippets.

@popensesame
Created May 1, 2019 15:00
Show Gist options
  • Save popensesame/e87ee2c58f04b5011fc0a599ef553d35 to your computer and use it in GitHub Desktop.
Save popensesame/e87ee2c58f04b5011fc0a599ef553d35 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script installs kubectl and minikube on a Linux machine.
# It assumes you are intending to use VirtualBox as the virtualization driver.
# VirtualBox must be installed or this script will fail.
#
# Install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/
# Install minikube: https://kubernetes.io/docs/tasks/tools/install-minikube/
#
# Exit codes:
# 123: Virtualization is not enabled in the BIOS.
# 137: VirtualBox is not installed.
# Make sure VT-x or AMD-v virtualization is enabled.
CHECK_VIRT=$(egrep --color 'vmx|svm' /proc/cpuinfo)
if [[ "$CHECK_VIRT" == "" ]]; then
echo "Virtualization is not enabled in the BIOS! Enable that first and run me again."
echo "See https://www.howtogeek.com/213795/how-to-enable-intel-vt-x-in-your-computers-bios-or-uefi-firmware/"
exit 123
fi
# Make sure VirtualBox is installed...
echo "Checking if VirtualBox is installed..."
VBoxManage --version > /dev/null 2>&1
VBOX_EXIT_CODE=$?
if (( "$VBOX_EXIT_CODE" != 0 )); then
echo "VirtualBox is not installed! Download it here: https://www.virtualbox.org/wiki/Downloads"
exit 137
else
echo "Found VirtualBox..."
fi
# Install kubectl, the CLI tool for running commands in a k8s cluster
echo "Checking if kubectl is installed..."
kubectl version --client > /dev/null 2>&1
KUBECTL_EXIT_CODE=$?
if (( "$KUBECTL_EXIT_CODE" != 0 )); then
echo "Installing kubectl..."
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
echo "kubectl installed."
else
echo "Found kubectl..."
fi
# Install minikube
minikube version > /dev/null 2>&1
MINIKUBE_EXIT_CODE=$?
if (( "$MINIKUBE_EXIT_CODE" != 0 )); then
echo "Installing minikube..."
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
&& chmod +x minikube
sudo cp minikube /usr/local/bin && rm minikube
echo "Minikube installed! Nice."
else
echo "Found minikube..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment