Monday 18 April 2022

CKA Kubernetes ( K8S ) Application Lifecycle Management

 The preparation for the CKA (Certified Kubernetes Administrator) requires lots of practice and practice. Fortunately, we have lots of online playgrounds to keep practicing, there are lots of free courseware available and lots of paid as well are available. In addition to that, we get two attempts to clear the exam




Rolling updates and rollback

• Rollout is the process of updating all the pods/replicas for a defined deployment
• Revision is a change happened in the deployment
• Deployment Strategey
○ Recreate - Destroys all the existing pod and then start creating new version of pods
○ Rolling Update - Each pod gets deleted and recreated with new version in a sequence 
• Under the hood, the deployment actually creates another ReplicaSet with the new version of the image and will bring down the pods in older ReplicaSet
• For reverting the new changes, we need to execute 'kubectl rollout undo deployment/my-deployment'. Now it actually switches back to old ReplicaSet

Command and Argument

• Difference between CMD and ENTRYPOINT in docker is
○ CMD will be executed as soon as the container starts. And we can override the whole command by passing in the 'docker run'
○ ENTRYPOINT - if given, the final command that will be executed will be the concatenation of ENTRYPOINT and CMD
• We can override both of these properties in docker run command
• We can override these in kubernetes container by specifying the 'command' and 'args' fields

spec:
  containers:
   -  image: ubuntu
      command: ["sleep"]
      args: ["1000"]
     

Environment Variables

• We can define using the 'env' property
• We can get the env var value from ConfigMap and Secret too

spec:
  containers:
   -  image: ubuntu
      command: ["sleep"]
      args: ["1000"]
      env:
      - name: APP_COLOR
         value: BLUE

ConfigMaps

• We can create using imperative and declarative way
• 2 steps
○ First we need to create the ConfigMap
○ Refer it in the POD

apiVersion: v1
kind: ConfigMap
metadata:
   name: app-config
data:
  APP_COLOR: blue
  APP_MODE: prod

apiVersion: v1
kind: pod
metadata:
spec:
   containers:
   - name: webapp
     image: webapp:v1
     envFrom:
     - configMapRef:
         name: app-config

Secret

• Secret are used to store sensitive information
• Can be Created in both imitative and declarative way
• In declarative way we should encode the value in base64 format
• The ConfigMap and Secret can be mounted as volume as well. In that case the properties needs to be accessed like a file /opt/app-secret-volume/DB_Host
• The value in the file should be encoded like echo -n 'root' | base64

apiVersion: v1
kind: Secret
metadata:
    name: app-secret
data:
   DB_PASSWORD: hjuvhw=

apiVersion: v1
kind: pod
metadata:
spec:
   containers:
   - name: webapp
     image: webapp:v1
     envFrom:
     -secretRef:
         name: app-secret
     volumes:
     - name: app-secret-volume
       secret: 
         secretName: app-secret

Multicontainer pod

• All the containers in the pod shares the same
○ network - accessible by localhost
○ storage
○ lefecycle
• InitContainers
○ The InitContainers are special containers which will be executed before the actual container starts
○ We can define multiple InitContainers and all of them will run in a sequence 

No comments:

Post a Comment