DEV Community

Cover image for Kubernetes for Beginner
Keshav Kumar
Keshav Kumar

Posted on

Kubernetes for Beginner

Before understanding kubernetes let's first understand why something like this ever came to existence. So running applications in containers is not a new concept but after Docker it became easy and popular to deploy applications through containers. If you don’t know what Docker is, I suggest you read this article first.
Pets Vs Cattle
But when more and more containers started getting deployed it became difficult for the operations team to manage all those. So it’s like pets and cattle thing when you have a pet you give them a name show and them love and when it falls ill you start getting panic but when you have thousands of containers running you start treating them like cattles you don’t care much if one or two are not behaving properly you just replace them with new one. Here the kubernetes is one who will be managing those cattles i mean those containers and that is why it is called a container orchestration tool.

History of Kubernetes

borg image
Kubernetes is not so old it was built by google so what happened is that google was actually running such container technology internally in the company for a really long time with the help of an engine called BORG. So with the knowledge of BORG they created another container orchestration tool kubernetes and donated it to CNCF in 2015.
CNCF is the Cloud Native Computing Foundation and kubernetes was the first project to graduate from there. Kubernetes is also known as k8s (pronounced as kates) because eight letters are present in between ‘k’ and ‘s’ in kubernetes.

Now when k8s started getting popular most of the cloud providers started providing native support for it like GCP provides GKE(Google Kubernetes Engine), Azure provides AKS(Azure kubernetes service), AWS provides EKS(Elastic kubernetes service) and since this project was open source so a large community from around the world started improving it.

Setting up the environment

Now we will set up the kubernetes in our local system. But if you face any issue always feel free to check the official documentation.
If you are running the k8s in your local system you need to set up kubectl which is a kubernetes command line tool that allows you to run commands against kubernetes clusters and minikube which provides a virtual environment for running clusters inside your computer.

Now you need to install minikube but remember before using minikube you need to have docker or some similar container runtime environment inside your computer.
Minikube setup guide
And everytime you power on your computer you need to start your minikube with the minikube start command, you can stop this with the minikube stop command and you can check its status with the minikube status command.
minikube start img

Getting started

Kubernetes does not provide any options to build images so you need to build it on your own and deploy it to either docker-hub or google container registry then k8s will pull it (download it) and start a container out of it.
When you deploy Kubernetes, you get a cluster and k8s never talks to containers directly, it is actually the node that hosts pods and containers runs inside the pod (we will learn about pods in later sections) and every application or service runs inside the container.
Kubernetes Cluster Image

Pods & Service

There are two types of nodes. The first one is the worker node and the other is the service node.
Worker node's job to run the application lets say you created a react app so the worker node will be looking at the pods inside which the react app container is present. A node may be a virtual or physical machine, depending on the cluster. Each node is managed by the control plane and contains the services necessary to run Pods and a Service is a method for exposing a network application that is running as one or more Pods in your cluster. It means that the service node will provide a port to connect your react app from the worker pod. It handles all those networking stuff internally. You don’t need to make any changes in your application to work inside the kubernetes cluster.
So you will be creating two yaml files one for service and other for worker pod and the kind of those files will be service and pod respectively as shown below.

Get the configuration files here

Commands

to start those pods you need to run but remember to run minikube start first
kubectl apply -f service.yaml
kubectl apply -f client-pod.yaml

Now you can check if those pods are running via
kubectl get pods
And to check that website you can visit your minikube ip colon 31010, here 31010 port because we have declared that in the yaml file.
Since my minikube ip is 192.168.49.2 so i will visit 192.168.49.2:31010 and to check your minikube ip just type minikube ip in your terminal and if your ip is 172.156.1.1 then you need visit here 172.156.1.1:31010
The nodeport range lies between (30000-32767) so you are free to use any by change these yaml files.

Dashboard

Dashboard
Kubernetes also provides a dashboard to manage your cluster through UI, to visit the dashboard you need to first setup the dashboard, don’t worry it's very easy
First you need to deploy the dashboard with this command
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
Then you need to run these two yaml files of admin-user and role-binding and then start the dashboard service with proxy.
kubectl apply -f admin-user.yaml
admin-user yaml file
kubectl apply -f role-binding.yaml

role-binding file
kubectl proxy
If you see “Starting to serve on 127.0.0.1:8001” then you can visit here http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
and see the cluster but if it’s not showing starting to serve… then may be you have made a typo or may be you have not started minikube, you can start minikube with minikube start
You can check status with minikube status
And you can stop it with
minikube stop.
There are some more commands like kubectl describe pod which provides the details of pod.
And to delete a pod just write kubectl delete pod
You can replace this pod with the actual pod name means the metadata from yaml file, for e.g kubectl delete task-client
I you like this please put a comment below and I will bring more such blogs then you can follow me on Linkedin, twitter and github.

Top comments (0)