Kubernetes Deployment
Kubernetes Deployment is a resource object in Kubernetes that provides declarative updates to applications. Deployments ensure that the application maintains a desired state and can automatically recover from failures. It allows you to describe an application’s lifecycle, including what images to use for the application, the number of desired replicas, and how to handle updates and rollbacks. When a deployment is created, behind the scenes, it creates and manages Replica Sets. A Replica Set ensures that the desired number of pod replicas as specified in the Deployment is running at all times.
🔔 Key components of Deployment file
💡 As with all other Kubernetes configs, a Deployment needs apiVersion, kind and metadata fields.
💡 Replicas: The ‘replicas’ field in a Deployment specifies how many copies (replicas) of the pod should be running. Kubernetes will automatically create or scale down pods to match the desired replica count.
💡 Template: A deployment defines a pod template that includes information about the container image, ports and other settings for the application.
💡 Labels and selectors: The connection is established by labels and selectors. Metadata part contains labels and spec part contains selectors. Deployment labels is used by service selector.
Commonly used kubectl commands
🔸 To apply the changes
kubectl apply -f deployment.yml
🔸 To see the deployment rollout status
kubectl rollout status <deployment/name of the deployment>
🔸 To get the description of the deployment
kubectl describe deployment
🔸 To see the created ReplicaSet
kubectl get rs
🔸 To see the created Pods
kubectl get pods
🔸 To get the description of Pods
kubectl describe pods <pod name>
🔸 To watch for pods
kubectl get pods -w
🔸 To list all resources in current namespace
kubectl get all
🔸 To list all pods in current namespace with more details
kubectl get pods -o wide
🔸 To scale a deployment
kubectl scale <deployment/deployment name> --replicas=<replica count>
Benefits of using Deployment:
- Declarative Configuration
- Self-Healing
- Auto-Scaling
- Version Control
- Zero-Downtime Updates