Welcome to blog post on hands-on learning with Kubernetes! In our previous article, we explored the architecture of this powerful tool, and now it's time to take our knowledge to the next level. Are you ready to get your hands dirty and set up a Kubernetes environment on your local machine? Let's dive into the world of minikube and learn how to deploy Kubernetes in a local environment.
What is minikube?
Minikube is a lightweight Kubernetes implementation that creates a one-node cluster on your local machine. This makes it easy to get started with Kubernetes development and experimentation, without having to set up a complex and expensive cluster environment.
Minikube is available for Linux, macOS, and Windows systems, and can be installed using a variety of methods, including package managers, Docker, and Snap. Once installed, you can start a Minikube cluster with a single command.
Minikube clusters are fully functional Kubernetes clusters, and you can use them to deploy and manage applications just like you would any other Kubernetes cluster. However, Minikube clusters are not designed to be used for production workloads.
Here are some of the benefits of using Minikube:
It is easy to set up and use.
It is lightweight and portable.
It is compatible with a variety of platforms.
It provides a fully functional Kubernetes environment.
It is free and open source.
Here are some of the use cases for Minikube:
Learning and experimentation with Kubernetes.
Developing and testing Kubernetes applications.
Debugging Kubernetes applications.
Running small-scale Kubernetes deployments.
Demonstrating Kubernetes to others.
Overall, Minikube is a valuable tool for anyone wanting to start Kubernetes development or experimentation. It is also a useful tool for Kubernetes users who need a lightweight and portable Kubernetes environment.
Features of minikube:
Supports the latest Kubernetes release (+6 previous minor versions): Minikube is always up-to-date with the latest Kubernetes release, so you can be sure that you are using the most recent features and bug fixes.
Cross-platform (Linux, macOS, Windows): Minikube can be run on any major operating system, so you can use it on your local machine or in the cloud.
Deploy as a VM, a container, or on bare metal: Minikube can be deployed in a variety of ways, giving you the flexibility to choose the best option for your needs.
Multiple container runtimes (CRI-O, containerd, docker): Minikube supports multiple container runtimes, so you can choose the one that you prefer.
Direct API endpoint for blazing-fast image load and build: Minikube provides a direct API endpoint for loading and building images, which can significantly improve performance.
Advanced features such as LoadBalancer, filesystem mounts, FeatureGates, and network policy: Minikube supports all of the advanced features of Kubernetes, so you can use it to develop and deploy complex applications.
Addons for easily installed Kubernetes applications: Minikube provides a variety of add-ons that can be easily installed to add new functionality to your Kubernetes cluster.
Supports common CI environments: Minikube can be used in common CI environments like Jenkins and Travis CI.
Minikube Installation Guide for Ubuntu
This guide provides step-by-step instructions for installing Minikube on Ubuntu. Minikube allows you to run a single-node Kubernetes cluster locally for development and testing purposes.
Pre-requisites
2 CPUs or more
2GB of free memory
20GB of free disk space
Internet connection
Container or virtual machine manager, such as Docker, QEMU, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware Fusion/Workstation
I'm using an EC2 instance to install and run Minikube.
The recommended EC2 instance type for Minikube is a t2.medium instance. This instance type has 2 vCPUs and 8 GB of memory, which is sufficient for running a Minikube cluster and a few workloads.
Task-01
Minikube Installation
- Create an EC2 instance as suggested above
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
Now, logout (use exit
command) and connect again.
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/stable.txt)/bin/linux/amd64/kubectl"
Check 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 start a single-node Kubernetes cluster inside a Docker container.
Step 7: Check Cluster Status
Check the cluster status with:
minikube status
You can also use kubectl
to interact with your cluster:
kubectl get nodes
Task-02:
Create your first pod on Kubernetes through minikube.
But first, let me clarify a bit about pods :
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers that are relatively tightly coupled.
To create a pod we need to create a yaml file. Here we are going to create a pod of nginx
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Apply the configuration using the kubectl
command:
kubectl apply -f pod.yml
To access the Nginx Pod, run the following command to access the Minikube VM:
minikube ssh
Once inside the Minikube VM, you can use curl
to access the Pod's IP address. Replace <pod_ip_address>
with the actual IP address of your Pod.
curl <pod_ip_address>
We have successfully completed the project and this can be a good addition in our resume as a beginner in devops. Thank you for following my journey until here.
Happy Coding!