About Me

Monday, 6 March 2023

kubernetes interview questions and answers

 Differences between Deployments and ReplicaSet is changes made to container are not reflected once the ReplicaSet is created

For example: This is my replicaset.yaml

apiVersion: apps/v1
kind: ReplicaSet

metadata:
  name: nginx-replicaset
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 5 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.13.2
        ports:
        - containerPort: 80

I will apply this replicaset using this command

kubectl apply -f replicaset.yaml
kubectl get pods
kubectl describe pod <<name_of_pod>>

So from pod definition, we can observe that nginx is using 1.13.2. Now let's change image version to 1.14.2 in replicaset.yaml Again apply changes

kubectl apply -f replicaset.yaml
kubectl get pods
kubectl describe pod <<name_of_pod>>

Now we don't see any changes in Pod and they are still using old image.


Now let us repeat the same with a deployment (deployment.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 5 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.13.2
        ports:
        - containerPort: 80

I will apply this deployment using this command

kubectl apply -f deployment.yaml
kubectl get pods
kubectl describe pod <<name_of_pod>>

Change the deployment.yaml file with some other version of nginx image

apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 5 # tells deployment to run 2 pods matching the template
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.14.2
            ports:
            - containerPort: 80

I will again apply this deployment using this command

kubectl apply -f deployment.yaml
kubectl get pods
kubectl describe pod <<name_of_pod>>

Now we can see these pods and we can see updated image in the description of pod

No comments:

Post a Comment

youtube devops topics

What is LDAP and Active Directory? How LDAP works and the structure of LDAP/AD? https://youtu.be/Xp9kLn9vRmw