JavaDream aws,javadream Learn Kubernetes Basics

Learn Kubernetes Basics

Hi all in this blog we ‘ll learn Kubernetes basics. Kubernetes is an open source platform that is use to deploy containerized application. Kubernetes was originally design by google but later it’s maintain by the cloud native computing foundation (CNCF).

In short Kubernetes is a container orchestrator. it mange the containers.

We need to understand some terminology of Kubernetes and they are given as below:

  • Deployment
  • Service
  • Pods

There are many others also like ReplicaSet, ConfigMap, ConfigSecret, Ingress controller, Persistence volume etc. We ‘ll cover these topics also but the topic that mentioned in list ( Deployment, Service, Pods) are the core of Kubernetes. Let’s learn Kubernetes basics terminology first

Deployment

Deployment in Kubernetes is like a controller that manages the pods. It also helps us in rolling update and maintain the replica set numbers. Let’s understand this rolling update first.

Rolling Update

Say you have a application running on Kubernetes cluster. And you done some changes in your application now you want to deploy the latest image. So instead of replacing all the pods that is on old version with new image pods it replace one by one means when you deploy new docker image it’s just create the new pod with that version first and once this new pod become up and healthy then only it remove the old pod. In this way we maintain zero downtime and your application always UP. Say if any issue comes with your new image and new pods are not able to run then it do not delete the old pods with old image until these new pods become healthy and running.

Replica Set

Replica Set in Kubernetes is a most helpful thing. It always ensure that the define number of pods replica must always be up. For example say you define replicas as 3 in deployment specification. It means at any time 3 pods of the deployment must be up and running. So we can say that replica set always make an eye on define number of pods and if any of them is down it create the new one and maintain this define number of pods up and running always.

We create the deployment in yaml file but if you don’t know anything and want to generate the deployment.yaml file you can use the below command.

kubectl create deployment nginx-springboot-app --image=nginx:latest --dry-run=client -o yaml > nginx-deployment.yaml

The above command just create a deployment file only. Just change the –image value with your docker images. As of now we just mention the nginx image there.

As we mention this command only create the deployment file not the deployment itself. If you want to create the deployment using this file use the below command.

kubectl apply -f nginx-deployment.yamlCode language: CSS (css)

Once you run the above command to create deployment. Use below command to get deployment details it helps us to see if deployment create successfully or not. And check the Ready column value.

kubectl get deploymentsCode language: JavaScript (javascript)

Service

In Kubernetes service is like an abstraction it helps to provide a stable network endpoint to access group of pods. As we know that pods are ephermeral in nature means they can die at anytime. And as they run at their internal IP once they die we also loose track of IP for that pod. Do you observe the problem here say if 100 pods are running for a deployment and they are ephermeral means they can die at any time and also it’s difficult to manage 100 pods with different IPs.

So here service comes into the picture it provide a static IP address to group of pods. So end-user know only this IP address he doesn’t care how many pods are running for a deployment and what’s the IP for that.

Service are mainly of 4 types that are given as below:

  • ClusterIP
  • NodePort
  • LoadBalancer
  • ExternalName

ClusterIP is the default type of service. Means if we don’t provide service type explicitly by default it ‘ll be ClusterIP. ClusterIP service basically use for internal access only inside the cluster. Means you can not access from browser it should be accessible only inside the cluster.

NodePort service helps to expose application to the end-user by browser. We just have to define the port with the IP of worker node of the cluster. Syntax is like below.

http://NodeIP:PORTCode language: JavaScript (javascript)

And port must be in the range of 30000 to 32767.

LoadBalancer is mostly used service type. Around 99.5% application use LoadBalancer service type to expose application to the end-user. It creates an external load balancer in cloud that serve the traffic to pods. Using LoadBalancer we can access application using static IP only no need to map any port.

The last one is ExternalName, it helps us to access external service by giving them an Internal DNS name inside our cluster.

So we have already created the deployment above means we have our pods running. Using service we can expose them to the external world. Use below command to expose deployment using service. We are using LoadBalancer service type.

kubectl expose deployment nginx-springboot-app --type=LoadBalancer --port=80 --target-port=80 --dry-run=client -o yaml > nginx-service.yaml

above command create the service yaml file only. For creating the service use the below command.

kubectl apply -f nginx-service.yamlCode language: CSS (css)

After running above command just run the below command and see the external-ip column value. Use this IP and try to access your application endpoint you must get the response from your application.

 kubectl get serviceCode language: JavaScript (javascript)

PODS

Pods is the smallest and most use deployable unit in Kubernetes. They are ephermeral in nature means they can die, restart or can be replace at any time and Kubernetes does not take any guarantee of pods. So we need to make sure that we always have persistence volume attached to them as they are ephermeral so our data can be lost at any time.

Hope you like this blog if you like please share this with others and help us to grow. Please share your feedback in our comment section.

If you need block on any specific topic you can mention that in our comment section we ‘ll try to cover that in our upcoming blog.

Others blog you may like

Redirect Http to Https protocol with the help of Nginx

Website hosting on AWS S3 bucket

Share with others

Related Post