Basics of k8 Deployment

  • You describe a desired state in deployment
  • Traditionally deployment a usually done by shell scripts which execute line by line from top to bottom
  • In k8 deployment, you don’t write that but instead, we describe how the deployment will be with the help of a YAML file (desired state) and k8 takes care of the reset
  • The deployment controller is the component that takes the deployment file and relays the information to POD and replica set about the deployment
  • Control loop components are the objects which which compare the actual state and the desired state and scales the application according to the need mentioned in the deployment yaml file

Benefits :

  • You can scale the application with n number of pods on demand

Deployment.yaml for a Image which is already present on the local system (Docker Desktop)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-boot-test
spec:
  replicas: 2
  selector:
    matchLabels:
      app: spring-boot-test
  template:
    metadata:
      labels:
        app: spring-boot-test
    spec:
      containers:
      - name: spring-boot-test
        image: spring_build_test:1
        ports:
        - containerPort: 9090

Running the deployment.yaml using kubectl

kubectl apply -f k8\deployment.yaml

Checking the deployment status

kubectl get deploy

Check the deployment description (Step1 – Debugging)

kubectl describe deployment spring-boot-test

Check the pods description (Step2 – Debugging)

kubectl get pods
kubectl describe pod spring-boot-test-7c9d4947dd-4lz9n

Check the logs of pods (Step3 – Debugging)

kubectl get pods
kubectl logs spring-boot-test-7c9d4947dd-4lz9n | tail -20

Summary :

  • How to Start a deployment
    • kubectl apply -f k8\deployment.yaml
  • How to delete a deployment
    • kubectl delete deploy spring-boot-test
  • How to check the status of deployment
    • kubectl get deploy
  • Details for debugging
    • Check Deployment
      • kubectl get deployments
      • kubectl describe deployments <deployment_name>
    • Check Pods
      • kubectl get pods
      • kubectl describe pods <pod_name>
    • Check Logs of pods
      • kubectl logs <pod_name>

Leave a Comment