Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Kubernetes-session-1-pod-replicaset-replica-controller

A Kubernetes pod is a collection of one or more Linux containers, and is the smallest unit of a Kubernetes application. Any given pod can be composed of multiple, tightly coupled containers (an advanced use case) or just a single container (a more common use case).

*** Official Pro Document:

https://kubernetes.io/docs/reference/kubectl/cheatsheet/


Pod will contain one or more container.

IF in pod when we have more than one containers those container we called as sidecar & Ambassador container etc...

Note: when container will create inside the pod it will create along with pod one volume knows as EmpDir.


##################Lets Play with Pod#########################

To get the dynamic declarative yaml file from kubectl command

kubectl run podname --image=nginx:version

Ex:

kubectl run nginxpod --image=nginx:latest

--dry-run it will give us the plan but it won't be execute

ex: kubectl run nginxpod --image=nginx:latest --dry-run=client

**To convert CMD command into yaml declarative way

kubectl run nginxpod --image=nginx:latest --dry-run=client -o yaml

Sample is:

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginxpod
  name: nginxpod
spec:
  containers:
  - image: nginx:latest
    name: nginxpod
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

* By default for pods restart policy will be always restartPolicy: Always
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginxpod
  name: nginxpod
spec:
  containers:
  - image: nginx:latest
    name: nginxpod
  restartPolicy: Always

To run a pod or k8 manifest in fast mode use the

$ echo "apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginxpod
  name: nginxpod
spec:
  containers:
  - image: nginx:latest
    name: nginxpod
  restartPolicy: Always" | kubectl apply -f -


pod/nginxpod created

$ kubectl get pods

NAME       READY   STATUS    RESTARTS   AGE

nginxpod   1/1     Running   0          6s

Troubleshoot a pod

kubectl describe pod podname -n namespace
kubectl logs  podname -n namespace

** To check the container logs
kubectl logs podname -c containername

Sample pod file:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginxpod
  name: nginxpod
spec:
  containers:
  - image: nginx:latest
    name: nginxpod
    volumeMounts:
    - mountPath: /test
      name: test-vol
  - image: rajeshsingam/prod-working-flask:latest
    name: dummytest
  volumes:
  - name: test-vol
    emptyDir: {}
  restartPolicy: Always  

========================Replica Set & Controller=============================


ReplicaSet is the next generation of Replication Controller. Replication controller is kinda imperative, but replica sets try to be as declarative as possible.
The difference should be insignificant in most cases. ReplicaSet has a generalized label selector. ReplicaSet should support all the features the replication controller supports.

ReplicaSet is a replacement for the Replica controller and supports richer expressions for the label selector. You can choose between 4 values of operators In, NotIng, Exists, DoesNotExist
The main difference between a Replica Set and a Replication Controller right now is the selector support
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

K8 Replication controller
ref
https://www.devopsschool.com/blog/difference-between-replicaset-and-replicationcontroller

It means that in aws how autoscalling works in the same way replication controller will works.

To manage pod we r using replication controller like scale up or scale down

K8 ReplicaSet:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: frontend
  labels:
    app: guestbook
    tier: frontend
spec:
  # modify replicas according to your case
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: php-redis
        image: gcr.io/google_samples/gb-frontend:v3

Pod controller we have 3 types


replication controller

replication set
deployment

1.replication controller:
it s like autoscaling which will monitor the pod depends on label which allocated to pod.

2. replications seT;
its a advance feature of replication controller which only difference is when reflection controller will manage only "single labels" by using
replication set we can manage the multiple labels in replication controller

another pont replication controller will get rollback but replication set we wont get roll back update

3.Deployment: real time all are using deployments only
we can over come above all issues using deployment
ref: https://www.mirantis.com/blog/kubernetes-replication-controller-replica-set-and-deployments-understanding-replication-options/


***RS main responsibility to handle the pods incremented and downgrade but the main problem is whenever we modified the configuration like changing the images those changes won't be reflect on browser while accessing
Drawback of RS is updating images it won't have feature of rollback in automatic way how we have in deployment it will only take care about pod count like increment and decrement.

** In set rolling update is not possible
Ref: https://rajeshsingamsetti.blogspot.com/2022/10/k8-session-3-replica-set-and-controller.html







Post a Comment

0 Comments

Ad Code

Responsive Advertisement