How to Install and Set Up Minikube for Local Kubernetes Development

KubernetesKubernetesBeginner
Practice Now

Introduction

This tutorial will guide you through the process of installing and setting up Minikube, a popular tool for running Kubernetes locally on your machine. By the end of this guide, you will have a fully functional Kubernetes development environment on your local system, allowing you to build, test, and deploy your applications with ease.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL kubernetes(("`Kubernetes`")) -.-> kubernetes/BasicCommandsGroup(["`Basic Commands`"]) kubernetes(("`Kubernetes`")) -.-> kubernetes/ConfigurationandVersioningGroup(["`Configuration and Versioning`"]) kubernetes(("`Kubernetes`")) -.-> kubernetes/BasicsGroup(["`Basics`"]) kubernetes/BasicCommandsGroup -.-> kubernetes/create("`Create`") kubernetes/BasicCommandsGroup -.-> kubernetes/get("`Get`") kubernetes/BasicCommandsGroup -.-> kubernetes/run("`Run`") kubernetes/ConfigurationandVersioningGroup -.-> kubernetes/config("`Config`") kubernetes/BasicsGroup -.-> kubernetes/initialization("`Initialization`") subgraph Lab Skills kubernetes/create -.-> lab-398366{{"`How to Install and Set Up Minikube for Local Kubernetes Development`"}} kubernetes/get -.-> lab-398366{{"`How to Install and Set Up Minikube for Local Kubernetes Development`"}} kubernetes/run -.-> lab-398366{{"`How to Install and Set Up Minikube for Local Kubernetes Development`"}} kubernetes/config -.-> lab-398366{{"`How to Install and Set Up Minikube for Local Kubernetes Development`"}} kubernetes/initialization -.-> lab-398366{{"`How to Install and Set Up Minikube for Local Kubernetes Development`"}} end

Understanding Minikube

Minikube is a popular open-source tool that allows developers to run a single-node Kubernetes cluster on their local machines. It is designed to be a lightweight and easy-to-use solution for developers who want to experiment with Kubernetes and build Kubernetes-based applications.

What is Minikube?

Minikube is a Kubernetes distribution that runs a single-node Kubernetes cluster inside a virtual machine (VM) or a container on your local machine. It provides a simple and convenient way to set up a Kubernetes environment for development and testing purposes, without the need to set up a full-fledged Kubernetes cluster.

Why Use Minikube?

Minikube is particularly useful for developers who want to:

  • Learn and experiment with Kubernetes without the complexity of setting up a multi-node cluster
  • Test and debug Kubernetes-based applications on their local machines
  • Develop and deploy applications to Kubernetes in a controlled environment

Minikube supports a variety of hypervisors, including VirtualBox, VMware, Hyper-V, and Docker, making it compatible with a wide range of operating systems, including Windows, macOS, and Linux.

Key Features of Minikube

  • Single-node Kubernetes cluster: Minikube runs a single-node Kubernetes cluster inside a virtual machine or container, providing a simplified and self-contained Kubernetes environment.
  • Hypervisor support: Minikube supports various hypervisors, including VirtualBox, VMware, Hyper-V, and Docker, allowing you to choose the best option for your local development environment.
  • Addons: Minikube comes with a set of built-in addons, such as a web-based Kubernetes dashboard, a container registry, and a DNS server, which can be easily enabled and configured.
  • Easy deployment: Minikube simplifies the process of deploying and testing Kubernetes-based applications on your local machine, making it a valuable tool for developers.

By understanding the basics of Minikube, you can set up a local Kubernetes environment and start exploring the world of container orchestration and deployment.

Installing and Configuring Minikube

Prerequisites

Before installing Minikube, make sure your system meets the following requirements:

  • Operating System: Ubuntu 22.04 LTS
  • Hypervisor: VirtualBox (or another supported hypervisor)
  • CPU: At least 2 cores
  • RAM: At least 4 GB

Installing Minikube

  1. Update the package index and install the necessary dependencies:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
  1. Download and install the latest version of Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
  1. Verify the installation by running the following command:
minikube version

You should see the installed version of Minikube.

Configuring Minikube

  1. Start the Minikube cluster:
minikube start

This command will create a single-node Kubernetes cluster on your local machine.

  1. Verify the cluster status:
minikube status

You should see the cluster is running and ready to use.

  1. (Optional) Enable Minikube addons:
minikube addons list
minikube addons enable dashboard

This will enable the Kubernetes dashboard addon, which provides a web-based user interface for managing your Kubernetes cluster.

  1. Access the Kubernetes dashboard:
minikube dashboard

This will open the Kubernetes dashboard in your default web browser.

By following these steps, you have successfully installed and configured Minikube on your Ubuntu 22.04 system, creating a local Kubernetes environment for development and testing purposes.

Running Kubernetes Locally with Minikube

Deploying a Sample Application

  1. Create a new Kubernetes deployment using the LabEx NGINX image:
kubectl create deployment labex-nginx --image=labex/nginx:latest
  1. Expose the deployment as a Kubernetes service:
kubectl expose deployment labex-nginx --type=NodePort --port=80
  1. Check the status of the deployment and service:
kubectl get deployment,service

You should see the LabEx NGINX deployment and service running in your Minikube cluster.

Accessing the Application

  1. Retrieve the URL to access the LabEx NGINX application:
minikube service labex-nginx --url

This command will provide the URL you can use to access the application in your web browser.

  1. Open the application in your web browser:
open $(minikube service labex-nginx --url)

You should see the LabEx NGINX welcome page.

Scaling the Application

  1. Scale the LabEx NGINX deployment to 3 replicas:
kubectl scale deployment labex-nginx --replicas=3
  1. Verify the scaled deployment:
kubectl get deployment labex-nginx

You should see that the deployment now has 3 replicas running.

Updating the Application

  1. Update the LabEx NGINX deployment to use a newer version of the image:
kubectl set image deployment/labex-nginx labex-nginx=labex/nginx:v2
  1. Monitor the rollout progress:
kubectl rollout status deployment labex-nginx

This will show the deployment updating to the new version of the LabEx NGINX image.

By following these steps, you have successfully deployed, scaled, and updated a sample LabEx NGINX application running on your local Minikube Kubernetes cluster.

Summary

In this tutorial, you have learned how to install and configure Minikube, a Kubernetes distribution that allows you to run a single-node Kubernetes cluster on your local machine. With Minikube, you can now develop, test, and deploy your Kubernetes applications without the need for a full-fledged Kubernetes cluster. By following the steps outlined in this guide, you have set up a powerful local Kubernetes development environment that will simplify your Kubernetes-based application development workflow.

Other Kubernetes Tutorials you may like