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â feature
Make sure you have a Kubernetes cluster set up, either locally or on a cloud provider.
Create a file named âdeployment.ymlâ with the following contents:
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-app
labels:
app: todo
spec:
replicas: 3
selector:
matchLabels:
app: todo
template:
metadata:
labels:
app: todo
spec:
containers:
- name: todo
image: rishikeshops/todo-app
ports:
- containerPort: 3000
Run the command âkubectl apply -f deployment.ymlâ to apply the YAML file to your Kubernetes cluster. This will create the Deployment.
Verify that the Deployment was created successfully by running the command âkubectl get deployment todo-appâ . This should show you the current number of replicas.
- Test the auto-healing feature by intentionally crashing one of the containers in the Deployment. You can do this by running the command âkubectl delete pod <podname>â, where <podname> is the name of one of the running pods. Kubernetes should automatically spin up a new pod to replace the one that was deleted.
- Now if you check the pods a one pod is getting terminated while a new pod is up and running to make sure there is always replicas=3.
Congratulations, youâve now deployed a todo-app with auto-healing feature.
Thank you for reading. I hope you now have a better understanding of Kubernetes.
Happy Learning :)