How to Install Kubernetes
How to Install Kubernetes? What is a Pod?
previously , I discussed on what is Kubernetes, and its architecture.Here , will discuss on how to install a Kubernetes cluster.
Ways to Install Kubernetes
There are different ways to install Kubernetes like:
Kubernetes using kubeadm
Kubernetes using Minikube
Kubernetes uses managed Platforms like EKS(AWS), AKS(Azure), and GKE(GCP).
Here, I will let you know how to install a K8s cluster using Minikube. Before that let's discuss the concept of Pods.
Pods
In general terms, a pod refers to a small, enclosed space or container. K8s gains the idea of the pods from this.
Pods are "Pods are the smallest deployable units of computing that you can create and manage in Kubernetes" according to the official documentation of Pods by k8s.
A pod is the smallest and simplest unit of deployment. It represents a single instance of a running process in the cluster. A pod encapsulates one or more containers, along with shared storage resources, network settings, and other specifications.
Minikube
Minikube is a tool that enables us to run a single-node Kubernetes cluster locally on your machine.
It is designed for development and testing purposes, allowing to quickly set up and experiment with Kubernetes without the need for a full-scale cluster.
All you need is Docker (or similarly compatible) container or a Virtual Machine environment, and Kubernetes is a single command away: minikube start.
Benefits of using Minikube
A few benefits of using Minikube are:
It is easy to install and use.
It runs on Windows, Mac, and Linux.
It supports a variety of Kubernetes features, including pods, services, and deployments.
It is a great way to learn about Kubernetes.
It is a great way to test your applications locally.
It supports VirtualBox, KVM, Hyper-V, and Docker.
Minikube supports various Kubernetes add-ons Kubernetes Dashboard, Metrics Server for resource monitoring, Ingress controller, and more that enhance the functionality of your local cluster.
Integrates with K8s command line kubectl.
Minikube allows you to manage multiple local Kubernetes clusters on the same machine.
Now let us learn how to install a minikube:
Tasks
Task 1: Install minikube.
To install minikube on our Linux machine, let us download the Minikube binary for Linux (amd64 architecture) from the specified URL.
The options -LO here signify: -L instructs the curl to follow redirects and -O instructs curl to save the downloaded file with the same name as the remote file.
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Now let us install the minikube from the downloaded binaries in the directory '/usr/local/bin/minikube':
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Now a prerequisite for using minikube, install Kubectl:
sudo snap install kubectl --classic
We are using snap package manager as we can install kubectl in a single command making the installation straight forward, without the need to manually add additional repositories or perform additional configuration steps.
However here's how you can install kubectl using apt-get package manager:
Let us start the minikube, initialize the Kubernetes cluster locally.
minikube start
Let us verify if the pods are created or not.
kubectl get pods
kubectl get namespace
There are no pods, but the namespaces are created. Let us create a new pod.
Task 2: Create your first pod on Kubernetes through minikube.
Let's create a pod using a Manifest file, i.e. declarative YAML file for K8s. Create a file named pod.yml and write the following:
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
To use this pod.yml file, we need to run:
kubectl apply -f pod.yml
Let us check if the pods are created:
kubectl get pods
Let's check if the pod we created is running locally or not:
minikube ssh
curl http://<Pod's_IP>:80
We have created an Nginx pod on Kubernetes using Minikube!