#Day32 : Launching your Kubernetes Cluster with Deployment

#Day32 : Launching your Kubernetes Cluster with Deployment

ยท

2 min read

What is Deployment in k8s

A Deployment provides a configuration for updates for Pods and ReplicaSets.

You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new replicas for scaling, or to remove existing Deployments and adopt all their resources with new Deployments.

Task-1:

Create one Deployment file to deploy a sample todo-app on K8s using "Auto-healing" and "Auto-Scaling" feature

  • add a deployment.yml file (sample is kept in the folder for your reference)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: django-todo-deployment
  namespace: django-todo-ns
  labels:
    app: django-todo
spec:
  replicas: 4
  selector:
    matchLabels:
      app: django-todo
  template:
    metadata:
      labels:
        app: django-todo
    spec:
      containers:
      - name: django-todo
        image: trainwithshubham/django-todo:latest
  • apply the deployment to your k8s (kubeadm) cluster by command kubectl apply -f deployment.yml

Verify it on node:

Detailed View of this code:

Here's a detailed explanation of the YAML file using stickers:

๐Ÿ”„ apiVersion: apps/v1: This line specifies the Kubernetes API version that this deployment will use.

๐Ÿ“Œ kind: Deployment: This line specifies that this YAML file defines a deployment object in Kubernetes. Deployments are used to manage and scale containerized applications.

๐Ÿ“ metadata: name: todo-app: This section specifies the metadata for the deployment object, including its name. In this case, the deployment is named "todo-app".

๐Ÿ“ spec: replicas: 2: The "spec" section of the YAML file specifies the desired state of the deployment. In this case, we want to run two replicas of the application.

๐Ÿ”Ž selector: matchLabels: app: todo: This section specifies the label selector for the deployment. It uses the label "app: todo" to match the pods that belong to this deployment.

๐Ÿ“ template: metadata: labels: app: todo: This section specifies the pod template for the deployment. It sets the "app" label to "todo".

๐Ÿ“ spec: containers: - name: todo image: rishikeshops/todo-app ports: - containerPort: 3000: This section specifies the container configuration for the deployment. It defines a single container named "todo" with the specified image and port number.

๐Ÿ“ autoscaling: enabled: true minReplicas: 2 maxReplicas: 10 targetCPUUtilizationPercentage: 50: This section specifies the autoscaling configuration for the deployment. When enabled, it will automatically adjust the number of replicas based on CPU utilization. The minimum number of replicas is 2 and the maximum number is 10. The target CPU utilization percentage is set to 50.

๐Ÿš€ Overall, this YAML file defines a scalable deployment for a todo app running in Kubernetes. By using the autoscaling feature, the deployment can automatically adjust the number of replicas based on demand, ensuring that the application is always available and responsive to users.

ย