Let’s read about minikube and implement k8s in our local machine
What is minikube?
Minikube is a tool which quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows. It can deploy as a VM, a container, or on bare-metal.
Minikube is a pared-down version of Kubernetes that gives you all the benefits of Kubernetes with a lot less effort.
This makes it an interesting option for users who are new to containers, and also for projects in the world of edge computing and the Internet of Things.
Features of minikube
(a) Supports the latest Kubernetes release (+6 previous minor versions)
(b) Cross-platform (Linux, macOS, Windows)
(c) Deploy as a VM, a container, or on bare-metal
(d) Multiple container runtimes (CRI-O, containerd, docker)
(e) Direct API endpoint for blazing fast image load and build
(f) Advanced features such as LoadBalancer, filesystem mounts, FeatureGates, and network policy
(g) Addons for easily installed Kubernetes applications
(h) Supports common CI environments
Installation
Step 1: Update System Packages
Update your package lists to make sure you are getting the latest version and dependencies.
sudo apt update
Step 2: Install Required Packages
Install some basic required packages.
sudo apt install -y curl wget apt-transport-https
Step 3: Install Docker
Minikube can run a Kubernetes cluster either in a VM or locally via Docker. This guide demonstrates the Docker method.
sudo apt install -y docker.io
Start and enable Docker.
sudo systemctl enable --now docker
Add current user to docker group (To use docker without root)
sudo usermod -aG docker $USER && newgrp docker
Step 4: Install Minikube
First, download the Minikube binary using curl
:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Make it executable and move it into your path:
chmod +x minikube
sudo mv minikube /usr/local/bin/
Step 5: Install kubectl
Download kubectl, which is a Kubernetes command-line tool.
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release
Check the above image ⬆️ Make it executable and move it into your path:
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
Step 6: Start Minikube
Now, you can start Minikube with the following command:
minikube start --driver=docker
This command will create a single-node Kubernetes cluster inside a Docker container.
Running Nginx using minikube
Step 1: Start Minikube
If Minikube is not running, start it using the following command:
minikube start
Step 2: Run Nginx Container
You can use the kubectl run
command to run an Nginx container without any YAML files. For example:
kubectl run nginx-container --image=nginx:latest --port=80
This command creates a Deployment and a Pod with the name, runs the Nginx container with the latest image, and exposes port 80.
Step 3: Expose Nginx Port
Next, you can expose the Nginx container’s port 80 to access it from your local machine:
kubectl expose deployment/nginx-container --type=NodePort --name=nginx-service
This command creates a service of type NodePort named nginx-service
that exposes the Nginx container's port 80.
Step 4: Find the NodePort
To find the NodePort assigned to the service, you can use the following command:
kubectl get svc nginx-service
Look for the NodePort value under the “PORT(S)” column.
Step 5: Access Nginx
Now, you can access Nginx in your Minikube cluster using the Minikube IP address and the NodePort. Get Minikube’s IP address:
minikube ip
Then, open a web browser and navigate to <Minikube-IP>:<NodePort>
(e.g., http://192.168.49.2:30896
). You should see the default Nginx welcome page.