Launching your First Kubernetes Cluster with Nginx running
Awesome! You learned the architecture of one of the top most important tools "Kubernetes"
What is minikube?
Minikube is a tool that 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
Supports the latest Kubernetes release (+6 previous minor versions)
Cross-platform (Linux, macOS, Windows)
Deploy as a VM, a container, or on bare-metal
Multiple container runtimes (CRI-O, containerd, docker)
Direct API endpoint for blazing-fast image load and build
Advanced features such as LoadBalancer, filesystem mounts, FeatureGates, and network policy
Addons for easily installed Kubernetes applications
Supports common CI environments
Install Minikube on your local or cloud Ubuntu
Prerequisites:
- Ensure that you have virtualization technology enabled on your machines, such as VirtualBox, VMware, or Docker.
Follow these steps to install Minikube on Linux (Debian/Ubuntu):
Update your system's package list:
sudo apt update
Install the required dependencies:
minikube needs a virtual machine to run in our case I install docker
sudo apt-get install docker.io # add docker in user group sudo usermod -aG docker $USER #Reboot system sudo reboot
Download Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Install Minikube
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Verify the installation by running the following command:
minikube version # This command should display the Minikube version if the installation was successful.
Start Minikube by running the following command:
minikube start
What is Kubeadm?
kubeadm is a tool provided by the Kubernetes project to simplify the process of setting up a production-grade Kubernetes cluster. It automates many of the manual steps involved in creating a cluster, such as initializing the control plane, joining worker nodes, and configuring networking.
Here are some key features and functionalities of Kubeadm:
Cluster Initialization: kubeadm helps initialize the control plane node of a Kubernetes cluster. It handles the generation of necessary certificates, API server configuration, and secure communication between cluster components.
Worker Node Join: Once the control plane is initialized, kubeadm provides a command to join worker nodes to the cluster. This command retrieves the necessary configuration and tokens required for a worker node to communicate with the control plane.
Networking Configuration: kubeadm can integrate with various network plugins to configure networking within the cluster. It supports popular options like Calico, Flannel, Weave, and more. By default, kubeadm uses the kube-proxy component for basic cluster networking.
Version Compatibility: kubeadm ensures that the version of Kubernetes being installed is compatible with the control plane. It checks for required dependencies and provides necessary warnings or recommendations during the setup process.
Cluster Upgrades: kubeadm supports cluster upgrades by providing commands to safely upgrade the control plane and worker nodes to a new version of Kubernetes. It follows specific upgrade procedures and checks compatibility to ensure a smooth transition.
Configuration File Generation: kubeadm generates a Kubernetes configuration file (
kubeconfig
) that allows you to interact with the cluster usingkubectl
. This file contains the necessary credentials and cluster information for authentication and authorization.
kubeadm is a powerful tool for creating and managing Kubernetes clusters. However, it focuses mainly on the control plane and worker nodes' setup, leaving other cluster components (such as networking and storage) to be configured separately. It is commonly used by system administrators, cluster operators, and anyone responsible for deploying and managing Kubernetes clusters in production environments.
Install kubeadm.
we need at least 2 virtual machines and launch 2 instances. One is t2.medium and the other is t2.micro or t2.medium
To install the Kubernetes cluster in both nodes we need CRI( CONTAINER RUNING INTERFACE ) for that we need to install docker in our nodes (Instances). so Container can run our machines.
Note:- when we are installing docker that time ContainerD will be installed automatically.
# run these command in both Master & Worker sudo apt update -y && sudo apt install docker.io -y # in the both node we have to update and install docker systemctl status docker # command to check docker install or not sudo systemctl start docker # and then sudo systemctl enable docker # sudo systemctl enable docker command After running this command, Docker will be set to start automatically whenever the system boots up.
Add Kubernetes Repository: To install kubeadm, you need to add the Kubernetes repository to your package manager. Run the following commands to add the Kubernetes repository:
# Both Master & Worker sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
After adding the Kubernetes repository, you can install kubeadm by running the following command:
sudo apt update -y sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Initialize the Cluster: Once kubeadm is installed, you can use it to initialize the control plane of your Kubernetes cluster.
#Run this command in Master node sudo su #This command allows you to switch to the root user kubeadm init # initializes the Kubernetes control plane on the current node. It sets up the necessary configuration and generates certificates for secure communication between cluster components. After running this command, you will receive instructions and a token to join worker nodes to the cluster. mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config #Creates the .kube directory in the user's home directory if it doesn't exist already. #Copies the configuration file for the Kubernetes cluster (usually located at /etc/kubernetes/admin.conf) to the .kube/config file in the user's home directory. #Sets the ownership of the copied configuration file to the current user. kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml #applies the Weave CNI (Container Network Interface) configuration by downloading the YAML file from the specified URL and deploying it to the Kubernetes cluster. Weave is a popular networking solution for Kubernetes clusters. kubeadm token create --print-join-command # generates a token and provides the necessary command to join worker nodes to the Kubernetes cluster. It prints the kubeadm join command with the required parameters, which you can run on worker nodes to join them to the cluster.
kubeadm token create --print-join-command--->this command generates a token eith ip & port
Enable mention port on Worker instance Security Groups Inbound rule
Now we need to setup our Worker node
sudo su kubeadm reset pre-flight #checks -----> Paste the Join command on worker node append --v=5 #at end
Now finally our both nodes are ready, to verify.
kubectl get nodes
Let's understand the concept of pod
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.
Create your first pod on Kubernetes
To create your first pod on Kubernetes, you'll need to define a Pod manifest file in YAML format and apply it using kubectl
. Here's an example of creating a simple NGINX web server pod:
Create a file named
nginx-pod.yaml
and open it for editing.Add the following content to the
nginx-pod.yaml
file:
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
# After creating this file , run below command:
# kubectl apply -f <yaml file name>
This manifest describes a pod with a single container using the NGINX image. The container listens on port 80.
Save and close the file.
Apply the pod manifest using
kubectl
by running the following command:kubectl apply -f nginx-pod.yaml #This command creates the pod described in the YAML file. If the pod creation is successful, you will see a confirmation message.
Verify that the pod is running by executing the following command:
kubectl get pods #This command lists all the pods in the default namespace. You should see your nginx-pod listed with a status of "Running."
Also, verify the running Docker container on the Worker node.
Thank you.......
Subscribe to my newsletter
Read articles from Dhwarika Jha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by