Mastering Kubernetes Deployments: A Comprehensive Guide πŸš€

Written by Sivaranjan

Β·

2 min read

Mastering Kubernetes Deployments: A Comprehensive Guide πŸš€

As a professional DevOps engineer, managing Kubernetes deployments efficiently is crucial. This article will guide you through creating and managing deployment.yaml files, scaling replicas, setting images at runtime, and more. Let's dive in! 🌊

1. Creating deployment.yaml πŸ“

First, let's create a basic deployment.yaml file for an Nginx deployment.


apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80

2. Scaling Up & Down Replicas πŸ“ˆπŸ“‰

To scale your deployment replicas up or down, use the following commands:

Scale Up:

kubectl scale deployment nginx-deployment --replicas=4

Scale Down:

kubectl scale deployment nginx-deployment --replicas=2

3. Setting Image Through Runtime πŸ”„

You can update the container image of your deployment at runtime:

kubectl set image deployment/nginx-deployment nginx=nginx:1.19.0

4. Rollout History πŸ“œ

To check the rollout history of your deployment, use:

kubectl rollout history deployment/nginx-deployment

5. Record Cause πŸ“

To record the reason for a deployment update, add the --record flag:

kubectl set image deployment/nginx-deployment nginx=nginx:stable-perl --record

6. Annotations 🏷️

Annotations can provide additional metadata to your resources. Add annotations to your deployment.yaml like this:

metadata:
  name: nginx-deployment
  annotations:
    description: "This deployment runs Nginx"

7. Rollout Previous πŸ”„

To rollback to the previous deployment, use:

kubectl rollout undo deployment/nginx-deployment

8. Rollout Registered First Version πŸ”„

To rollback to a specific revision, use:

kubectl rollout undo deployment/nginx-deployment --to-revision=1

Checking All Resources & Types πŸ› οΈ

To see all your resources and their types:

kubectl get all

Executing deployment.yaml πŸš€

To create the deployment from your deployment.yaml file:

kubectl apply -f deployment.yaml

Checking Pod & Node Status πŸ”

To check the status of your pods and nodes:

kubectl get pods
kubectl get nodes

Checking Deployment & ReplicaSet πŸ”

To check the status of your deployment and its replicaset:

kubectl get deployments
kubectl get replicasets

By mastering these commands and techniques, you'll be well-equipped to manage Kubernetes deployments like a pro. Happy deploying! πŸš€βœ¨

Feel free to share your thoughts or ask any questions in the comments below! 😊

Β