Shashikant shah

Wednesday, 16 December 2020

What is JOBS in Kubernetes. Part-10

 

The main function of a job is to create one or more pod and tracks about the success of pods. They ensure that the specified number of pods are completed successfully. When a specified number of successful run of pods is completed, then the job is considered complete.
















Run to completion
1.Each job creates one or more pods.
2.Ensures they are successfully terminated.
3.job controller restarts or rescheduled if a pod or node fails during execution.
4.can run multiple pods in parallel.
5.can scale up using kubectl scale command.

Use cases:
1.one time initialization of resources such as databases.
2.multiple workers to process messages in queue.












restartPolicy: Never →This condition of image restart is given as never which means that if the container is killed or if it is false, then it will not restart itself




















What is DaemonSet in kubernetes Part-09

 How do you deploy only one pod on every node and particular cluster.

i) A DaemonSet ensures that
 all (or some) Nodes run a copy of a Pod.
ii) As nodes are added to the cluster, Pods are added.
iii) As nodes are removed from the cluster, those Pods are garbage collected.
iv) Deleting a DaemonSet will clean up the Pods it created.
Use Cases:
i)Node monitoring daemons: Ex: collectd.
ii) Log collection daemons: Ex: fluentd.
iii) Storage daemons: Ex: ceph

1.Fluentd pods launch all worker node.
# vim fluentd-ds-allnodes.yaml


# kubectl apply -f fluentd-ds-allnodes.yaml --dry-run=client
# kubectl get ds




# kubectl get pods




# kubectl describe ds fluentd-ds












2.Deploy pod on “subset” of worker nodes inside k8s cluster using DaemonSet

i) attach label to the nodes.
# kubectl get nods
# kubectl label nodes worker1.example.com worker2.example.com disktype=ssd
# kubectl get node --show-labels












# kubectl get ds



# kubectl get pods -o wide





Tuesday, 15 December 2020

What is a deployment in Kubernetes Part-08

 What is a deployment in kubernetes ?

1.Deployment can scale up/Down replicas of Pods.
2.multiple replicas.
3.Upgrade/Rollout.
4.Rollback.
5.pause and resume.

Deployment Strategies types :-

1.Recreate :- In this type of very simple deployment, all of the old pods are killed all at once and get replaced all at once with the new ones.


2.RollingUpdate ( Ramped or Incremental ) :-

The rolling deployment is the standard default deployment to Kubernetes. It works by slowly, one by one, replacing pods of the previous version of your application with pods of the new version without any cluster downtime.


3.Canary :-

10 instances, first 2 instance deployed new version & test is done then new version deployed on 8 instances. Full deployment has been done, after that old version instance will be deleted.

 

4.blue / Green :-

In a blue/green deployment strategy (sometimes referred to as red/black) the old version of the application (green) and the new version (blue) get deployed at the same time. When both of these are deployed, users only have access to the green; whereas, the blue is available to your QA team for test automation on a separate service or via direct port-forwarding.












1.Deployments – Manifest file.


2.Deployments – Create and Display.

# kubectl create -f nginx-deploy.yaml

# kubectl get deploy -o wide



# kubectl get rs -o wide (deployment has been generate selector & label pod-template-hash=5878ddd45b)




# kubectl get pods --show-labels (deployment has been generate selector & label pod-template-hash=5878ddd45b)




3.Desployments – Describe



 

4.Update nginx:1.7.9 -> nginx:1.9.1

If any changes in pods like images then trigger rollout.









5.uses maxSurge and maxUnavailable in RollingUpdate strategy.

maxSurge :- deployment time how many new pods running, mention like 25% and number of pods.

maxUnavailable :- deployment time how many old pods shutdown, mention like 25% and number of pods.






















Add maxSurge
























When deployment is there, 25% will be unavailable pods, and 25% will be new pods.


6.How to Rollback deployment.

i) store to comment use --record.

history comments By default its store 10, if increase limit Add "revisionHistoryLimit: 20" under "spec" in yaml file. 

# kubectl apply -f nginx-deploy.yaml --record

# kubectl rollout history deploy nginx-deploy

deployment "nginx-deploy" successfully rolled out

# kubectl rollout status deploy nginx-deploy






OR
ii) Deployment comment line add in yaml file :-

# vim nginx-deploy.yaml file
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
  labels:
    app: nginx-app
  annotations:
    kubernetes.io/change-cause: "nginx:1.7.9 deployed"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-app
 
#  kubectl apply -f nginx-deploy.yaml
 
# kubectl rollout history deploy nginx-deploy








7. How to Undo (Rollback) process.

Nginx:1.9.1 -> Nginx:1.7.9

# kubectl rollout history deploy nginx-deploy






i) Need to previous version using undo command.

# kubectl rollout undo deployment nginx-deploy


 




ii) using undo command with Revision no.

# kubectl rollout undo --help

# kubectl rollout undo --to-revision=2 deploy nginx-deploy

iii) Pause and Resume deployment:-

 # kubectl rollout pause deployment nginx-deploy

# kubectl rollout resume deployment nginx-deploy

6. Deployment Scale Up/Down & Delete.


















# Delete deployment.



Monday, 14 December 2020

What is a ReplicaSet in Kubernetes Part-07

 What is a ReplicaSet

Replica set, also termed as rs in short, is almost same as the replication controller is, only with a single difference. The replica set are also known as next generation replication controller. The only difference between replica set and replication controller is the selector types.


Labels are use pods in pods and Selector is used in RC/RS.


ReplicaSet use Set-based operators and replicationController use Equality-based.


What is difference between match operators when use in replicaSet and replicationController.


Use sample matchLabels :


# kubectl get rs -o wide --show-labels

# kubectl get rs -o wide --show-labels


ReplicaSet use MatchExpressions operator  :-

1.“In” operator :- Search label in running Pods when found labels and add pods in replicaSet.

2.”NotIn” operator :- ignore labels.


# kubectl get rs  -o wide --show-labels


# kubectl get pods --show-labels













 


 



Labels and multiple labels Part-05

How to add lable for pods in yaml file.









# kubectl apply -f firstpods.yaml 

# kubectl get pods -o wide --show-labels

# kubectl get pods --show-labels



How to add lable though command.

# kubectl label pod <pod_name>  <env=testing>

# kubectl get pods --show-labels



Multiple label add for pods in yaml file.






How to edit/replace name “env=testing” label to “env=prod” label.

# kubectl edit pods nginxpod

# kubectl label --overwrite pod nginxpod env=prod

How to delete “env=testing” label.

# kubectl label pod nginxpod env-

How to add label for all pods.

# kubectl  label --all status=xyz





Sunday, 13 December 2020

What is repplicationController in Kubernetes. Part-06

 

1.Replication controller



i) The replication controller monitors pods and automatically restarts them if they fail. 

ii) (Replication controller) selector name  match to (pods) label name.  

iii) Replication controllers and pods are associated with “labels”.

iv) Creating a “rc” with count of 1 ensure that a pod is always available.

v) If the whole node fails, the replication controller  respawn all the pods of that node on some different node.


There are two option for add lable and selector in RC.yml files.
First option :-
spec:
  replicas: 4         # 4 replica pods
  template:
    metadata:
      name: firstpod  
      labels: 
       type: app     # pods label name & default use rc selector name.

Second option add selector
spec:
  replicas: 4         # 4 replica pods
  selector:
           type: app  # use rc selector name.
  template:
    metadata:
      name: firstpod  
      labels: 
       type: app    # pods label name & default .





















Check rc label and selector.

# kubectl get rc -o wide --show-labels


Check the pods label.

# kubectl get pods -o wide --show-labels




Help for how to create rc yaml file.

# kubectl explain rc

OR

# kubectl explain rc  --recursive | less

Check rc.yaml file
# kubectl apply -f rc.yaml --dry-run=client

Create a replicationController
# kubectl  appliy  -f rc.yaml
# kubectl get rc
# kubectl get pods
# kubectl get pods --show-labels
# kubectl get pods -l type=app
# kubectl describe rc  <rc_name>
# get pods  -o wide --watch
 
Scaling up
# kubectl scale rc firstrc --replicas=5
 
Scaling down
# kubectl scale rc firstrc --replicas=4
 
ReplicationController edit
# kubectl edit <rc_nmae>
 
Replace rc configuration and edit yaml file.
# vim  rc.yaml
# kubectl apply -f rc.yaml
replicationcontroller/firstrc configured
 
Delete ReplicationController
# kubectl  delete  -f  rc.yaml