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:
Step 1: Create a YAML file name deployment.yml and add the following content.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx-container
image: nginx:latest
- Step 2: Apply the file using the following command.
kubectl apply -f deployment.yml
- Step 3: Verify that Deployment is created and running.
kubectl get deployments
- Step 4: To check whether all pods are running or not also to display ip address.
kubectl get pods -n nginx -o wide
- Step 5: Get all descriptions about the running pods.
kybectl describe deployment nginx-deployment -n nginx
What is auto-healing?
If a container fails, Kubernetes automatically redeploys the afflicted container to its desired state to restore operations.
To test this feature, you can manually delete one of your Pods by running:
kubectl delete pod <pod_name>
- List all running pods.
Use kubectl delete pod.
Now when you'll list all pods running on the server there wiil be a new pod created automatically.
What is auto-scaling?
It is a feature in which the cluster is capable of increasing the number of nodes as the demand for service response increases and decrease the number of nodes as the requirement decreases.
kubectl autoscale deployment todo-app --min=1 --max=5 --cpu-percent=50
Conclusion:
We've Created a Kubernetes pod with auto-scaling and auto-healing capabilities is a crucial step in building a resilient and efficient containerized application infrastructure