Skip to content

How to Setup Kubernetes Cluster with Minikube on Ubuntu

Advertisement

Hey everyone! Today, I’m going to show you how to set up a Kubernetes cluster using Minikube on your Ubuntu system with Docker or VirtualBox as the driver. No worries if you’re new – I’ll keep it simple, like explaining it over a cup of tea! Kubernetes is great for managing containerized apps, and Minikube lets us run it locally.

I’m testing this on an Ubuntu virtual machine that uses Docker. You can use the VirtualBox driver instead of Docker if you prefer. Let’s get started!

What You’ll Need Before Starting

Before we begin, let’s gather our tools – like prepping ingredients for dosa!

  • Ubuntu System – I’m assuming Ubuntu 24.04 or 22.04 (most versions should work).
  • Docker – We’ll use this instead of VirtualBox to run Minikube.
  • Minikube – This runs our Kubernetes cluster locally.
  • kubectl – A command-line tool to manage your Kubernetes cluster.
  • Internet Connection – For downloading stuff.

Step 1: Update Your System

First, let’s update Ubuntu to make sure everything’s fresh:

sudo apt update && sudo apt upgrade -y

This grabs the latest package info and updates your system. The -y says “yes” to everything automatically.

Step 2: Install Docker (or VirtualBox)

If you want to use VirtualBox as the driver, install it on your Ubuntu system by following this link: https://tecadmin.net/install-oracle-virtualbox-on-ubuntu/

Since we’re using Docker as the driver, let’s install it:

Add Docker’s official repository:

sudo apt install -y curl
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Add your user to the Docker group so you don’t need sudo every time:

sudo usermod -aG docker $USER

Log out and back in (or reboot) for this to take effect. Then verify Docker:

docker --version

If you see a version number, Docker is ready!

Step 3: Install Minikube

Now, let’s install Minikube – the star of our setup!

Download the latest Minikube:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

Move it to a system path and make it executable:

sudo install minikube-linux-amd64 /usr/local/bin/minikube

Check if it’s installed:

minikube version

If you see a version, Minikube is good to go!

Step 4: Install kubectl

kubectl is our Kubernetes remote control. Let’s set it up:

Download the latest version:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

Make it executable and move it:

chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Verify it:

kubectl version --client

If you see version info, it’s working!

Step 5: Start Minikube Cluster with Docker

Time to fire up the cluster! Since we’re using Docker, we’ll tweak a system setting first to avoid permission issues:

sudo sysctl fs.protected_regular=0

This command fixes a potential issue where Minikube can’t access certain files due to Ubuntu’s security settings. Now, start Minikube:

minikube start --driver=docker

This uses Docker as the driver. It’ll take a minute to download images and set up the cluster. Once done, you’ll see a success message.

Step 6: Check Your Cluster

Let’s confirm everything’s running smoothly:

kubectl cluster-info

You’ll see details like the master and KubeDNS addresses. Also, check the nodes:

kubectl get nodes

If you see minikube with a Ready status, your cluster is up!

Step 7: Play Around (Optional)

Let’s deploy a quick app to test it:

kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080

Get the URL to see it in action:

minikube service hello-minikube --url

Copy the URL (like http://192.168.49.x:xxxxx), paste it in your browser, and you’ll see a simple page!

Stopping Minikube

When you’re done, stop the cluster to free up resources:

minikube stop

To remove it completely:

minikube delete

Wrapping Up

That’s it, folks! You’ve set up a Kubernetes cluster on Ubuntu using Minikube with Docker. It’s like having a mini cloud on your machine – pretty neat, huh? Now you can play with Kubernetes, deploy apps, and learn more. If you hit any bumps, just search online or ask around – the community’s got your back. Happy experimenting!

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top