0% found this document useful (0 votes)
8 views5 pages

52

Kubernetes (K8s) is a container orchestration tool that facilitates the management of microservices in applications like e-commerce websites by allowing dynamic scaling of specific functionalities as needed. It organizes applications into clusters with master and worker nodes, uses pods as runtime environments for containers, and employs services for load balancing. Key commands include 'kubectl' for interacting with K8s, and deployments ensure that the desired number of pods are always running, while labels help identify and manage pods within deployments.

Uploaded by

gegoyo9715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

52

Kubernetes (K8s) is a container orchestration tool that facilitates the management of microservices in applications like e-commerce websites by allowing dynamic scaling of specific functionalities as needed. It organizes applications into clusters with master and worker nodes, uses pods as runtime environments for containers, and employs services for load balancing. Key commands include 'kubectl' for interacting with K8s, and deployments ensure that the desired number of pods are always running, while labels help identify and manage pods within deployments.

Uploaded by

gegoyo9715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

=============================

52
=============================

Why K8s is useful?

ie: Take a ecommerce website like Flipkart


Flip kart different micro services like
-Payments
-logins
-registrations
-sections
etc etc

What if there is an offer on a certain day or users who registerday on a


particularday get offer
then the load will increase on that day for registrations, using k8s we can
increase the capacity on that 1 particular section only
We can increase the capacity of any particular functionality as required, All these
are running on the same machine but any particular section can be increased because
it is loosely coupled

Docker is a software to impelement micro services and an ochestration service is


needed
ie:
-some micro service needs multiple replicas and scaling
-how to delpoy only order managament changes
-Particulat micro service has died and automatically has to be detected
-how to distribute the load

So to orchestrate this we need K8s

-------------------------------------------------------------

Cluster
==> Master
apiserver ( runs on 6443 port number)
etcd
scheduler
controller

==> Worker Nodes


kubelet
kubeproxy

ie:

Master node
WN1
WN2

xmachine wants to interact with kubetnetes machine, so in x machine client software


is required which is kubectl
kubectl by default will send request to port 6443

Xmachine
Kubectl

now assume there are three clusters

Cluster1
Cluster3
Cluster2

When we are connecting with these clusters using kubectl how will it authenticate?
There is something called certificate (similar to private key)
In certificate there are all the details, which port number it needs to send and
which port number

All kubernetes commandsstart with kubectl in a cluster we always interact with


Master

------------------------------------------------------------

Whenever is cluster is created there are 4 Namespaces, There are virtual rooms
The cluster is internally divided into 4 namespaces
We can create our own name spaces depending on the requirement

1)default
2)kube-node-lease
3)kube-public
4)kube-system

------------------------------------------------------------
Ultimately the purpose of K8S is to create pods

POD is a runtime environment for containers

The contain is inside Pod and the image is inside the container
The container has to be given a name unlike docker where the names were
automatically assigned

"kubectl get pods" - gives you the details of the pods in the machine
In the above command the name space is not given so it will search in default and
if there are no pods then shows empty

"kube get pods -n kube-system" (-n will allow you to use a name space, can be used
to check any names space)

"kube get pods -n kube-system -o wide" (-o wide will give additional information
like pod ip and node in which pods are running)

"kubectl" (displays all the commands)

"kubectl -run --help" (run is to create a pod and --help gives more details of how
run can be used in many ways)

"kubectl -run pd1 --image=nginx" (Creating a pod names pd1 using nginx image)

----------------------------------

DEPLOYMENT
----------
Deployment ensures that your pod is in running condition, If a pod dies then it
will automatically create another one
so deployment ensures that desired no of pods are in running condition

hierarchy
will create
Deployments=======>Replicaset==>Pods==>containers==>images

run command is only used for creating a pod, everything else will use create
command

"kubectl create deployment dep1 --image=nginx"

If the no of replicas required is not entered then only 1 will be created

"kubectl create deployment dep1 --image=nginx --replicas=2"


now it will create 2 pods and ensure that they are in running condition

Now 2 pods will be created inside the deployment and if one of the pod is deleted
or died then automatically another will be created

-----------------------------
Service
--------

To access POD application we need to create a service and 2nd thing it will do the
load balancing activity

Types of services

1)Cluster IP = If service type is cluster IP then pod app is only accessable only
within a cluster not from outside
2)Nodeport
3)Loadbalancer

The important thing is if you want to access PODS from within the cluster or
outside the cluster

"kubectl expose"

ie; showing load balancer as an example for service

Gets req to sends to


(80) ELB ==========> I1(8080)
I2(8080)
I3(8080)

Laptop ====> (80) ELB

simillarly

Services ===> port(8080)==>


targetport==>(80) (basically application is running on 80
port)

"kubectl describe" (Describes everything)

this command can be used in many ways


ir:

kubectl describe pods


kubectl describe services
kubectl describe replicaset
kubectl describe nodes
and many more

---------------------
Labels
---------------------
Assume there are 2 deployments and 6 pods

dep1
dep2

PD1
.
.
.
PD6
how will kubernetes know hich pods belong to which deployments?

We use labels.

labels are similar to Tags in aws

creating a label and how to attach them to pods

"kubectl get pods --show-labels" (to display labels)


"kubectl get deployment --show-labels"
"kubectl label pod pd1 app=nb" (giving pod names pd1 a label which is app=nb)
"kubectl label pod pd1 app=abc --overwrite" (overwritting a previously existing
label)
""kubectl label pod pd1 app-"" (adding - after the label name removes it here a
label names app is being removed)

***Assume you have 4 replicas running and now you remove label of 1 pod then
immediately another pod will be created
Kuberneted will identify it's pods using labels

If the unlabeled pod is labeled again with the same label then according to
Kubernetes only 4 replicas are requires and this new one makes it 5 do it will
automatically delete 1 POD

------------------------------
Few more commands
------------------------------

"kubectl scale deployment/dep1 --replicas=8" (Increases pods to 8 or any desired


number)
"kubectl scale deployment/dep1 --replicas=2" (Decreases pods to 2 or any desired
number)

-------------
Errors
-------------

1)Crahloopbackoff

Pd1=>
C1
=> Image

Here When container is creater then Entry point or CMD is executed and if there is
something wrong with it then we will get error
So check for errors in Images, K8s responsibility is only to orchestrate it

So to check further details like Image inside the pod and nodes use

"kubectl describe pod pd1 | more"

Kubernetes always tries to run containers and if a container dies then another will
be created again and again

This is crash back loop error : Container is started then it dies and kubernetes
tried to create another one again
The problem is with the image and not kubernetes so check the dockerimage

2)Image pull back offer

Assume you pull an image calle ubuuntu


There will be an error because of spelling mistake

This request goes into API server in master and stored in etcd
so this can be edited using

"kubectl edit pod pd3"

The result will be shows in yaml script


Then the image can be edited just like editing in a linux vim editor and save

You might also like