Day 31 : Launching your First Kubernetes Cluster with Nginx running
In last part, We learned the architecture of one of the top most important tool “Kubernetes”. Now let’s move forward!
Welcome to Day 31 of our Kubernetes journey! Today is an exciting day as we take a significant step forward in our exploration of Kubernetes. In this article, we will guide you through the process of launching your very first Kubernetes cluster and getting Nginx, the popular web server, up and running on it.
Let’s read about minikube and implement *k8s* in our local machine
1) 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.
2) What are features of minikube?
some of the minikube features are listed below -
(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
3) What is Kubectl used for?
Kubectl lets you run commands against Kubernetes clusters. You can make use of Kubectl to deploy applications, inspect and handle cluster resources, and view logs.
Tasks :-
Task 1) Install minikube on your local
For installation, you can Visit this page (https://minikube.sigs.k8s.io/docs/start/).
If you want to try an alternative way, you can check [this](https://k8s-docs.netlify.app/en/docs/tasks/tools/install-minikube/)
Download the minikube by commands listed in above article
Step 1) After downloading, Start your cluster
From a terminal with administrator access (but not logged in as root), run:
minikube start
Step 2) Interact with your cluster
If you already have kubectl installed, you can now use it to access your shiny new cluster:
kubectl get po -A
Alternatively, minikube can download the appropriate version of kubectl and you should be able to use it like this:
minikube kubectl -- get po -A
Initially, some services such as the storage-provisioner, may not yet be in a Running state. This is a normal condition during cluster bring-up, and will resolve itself momentarily. For additional insight into your cluster state, minikube bundles the Kubernetes Dashboard, allowing you to get easily acclimated to your new environment:
minikube dashboard
This will automatically open a web page in browser
Step 3) Deploy a application
Services
A)Create a sample deployment and expose it on port 8080:
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
kubectl expose deployment hello-minikube --type=NodePort --port=8080
B) It may take a moment, but your deployment will soon show up when you run:
kubectl get services hello-minikube
C) The easiest way to access this service is to let minikube launch a web browser for you:
minikube service hello-minikube
Alternatively, use kubectl to forward the port:
kubectl port-forward service/hello-minikube 7080:8080
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 which are relatively tightly coupled.
The following is an example of a Pod which consists of a container running the image nginx:1.14.2
.
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
To create the Pod shown above, run the following command:
kubectl apply -f https://k8s.io/examples/pods/simple-pod.yaml
You can read more about pod from [https://kubernetes.io/docs/concepts/workloads/pods/]
Task-2) Create a nginx pod on Kubernetes through minikube.
Create a pod for nginx with name pod.yml
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>
kubectl apply -f pod.yml
The below image shows that your nginx pod is created
Let us check if the pods are created:
kubectl get pods
kubectl get pods -o wide
Let’s check if the pod we created is running locally or not:
minikube ssh
curl http://<Pod’s_IP>:80
We have successfully created an Nginx pod on Kubernetes using Minikube!