Mastering Deployments in Kubernetes
Mesrar
Posted on February 1, 2024
Deployments in Kubernetes play a pivotal role in managing scalable and reliable applications. In this guide, we'll delve into essential commands and operations related to Deployments, empowering you to efficiently roll out and manage application updates.
Key Operations
Create a Deployment
Create a simple deployment using the kubectl create deploy command:
kubectl create deploy nginx --image=nginx --replicas=2
View Deployments
Get a list of deployments in the current namespace:
kubectl get deploy
For deployments in a specific namespace:
kubectl get deploy -n <namespace-name>
Retrieve detailed information about a specific deployment:
kubectl get deploy <deployment-name>
kubectl get deploy <deployment-name> -o yaml | more
kubectl get deploy -o wide
Apply Deployment from YAML
Apply a deployment defined in a YAML file:
kubectl apply -f deploy.yaml
To record the change cause in revision history:
kubectl apply -f deploy.yaml --record
Deployment Rollout Status
Check the rollout status of a deployment:
kubectl rollout status deploy <deployment-name>
Deployment Rollout History
View the revision history of a deployment:
kubectl rollout history deploy <deployment-name>
For detailed history of a specific revision:
kubectl rollout history deploy nginx --revision=2
Rollback Deployment
Rollback a deployment to a previous revision:
kubectl rollout undo deploy <deployment-name>
Or, rollback to a specific revision:
kubectl rollout undo deploy <deployment-name> --to-revision=1
Pause and Resume Deployment
Pause a deployment to apply multiple fixes, then resume to start a new rollout:
kubectl rollout pause deploy <deployment-name>
kubectl rollout resume deploy <deployment-name>
Delete Deployment
Delete a deployment:
kubectl delete deploy <deployment-name>
Scaling a Deployment
Scale up or down a deployment:
kubectl scale deploy <deployment-name> --replicas=3
Create a Deployment from YAML
Create a deployment using YAML definition:
kubectl create deploy <deployment-name> --image=redis -n <namespace-name>
Edit a Running Deployment
Make changes to a running deployment:
kubectl edit deploy <deployment-name> -n <namespace-name>
Important Properties
Deployment strategies and properties to remember:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
Type: RollingUpdate:
Specifies the update strategy as RollingUpdate, which means that the deployment process will replace old pods with new ones in a rolling fashion, ensuring the availability of the application during the update.
RollingUpdate
Configuration:
maxUnavailable: 0
: This setting indicates the maximum number or percentage of pods that can be unavailable during the update. A value of 0 means that no pods are allowed to be unavailable at any point during the rolling update. This ensures high availability as the new pods are gradually introduced, and the old ones are terminated.
maxSurge: 1
: This setting indicates the maximum number or percentage of new pods that can be created above the desired number of replicas. In this case, a value of 1 means that only one additional pod is allowed to be created during the update process. This controls the rate at which new pods are introduced, preventing any sudden spikes in resource usage
Keys follow camel case naming convention, and values follow initials in uppercase convention.
Additional Insights
Deployments automatically create a ReplicaSet, which, in turn, creates pods.
When creating or updating images in a deployment, a new rollout triggers, creating a new deployment revision.
Identify problematic deployments by checking the READY status. The number of containers running may be less than desired.
Mastering these deployment operations ensures smooth application updates and scalability in your Kubernetes environment.
Happy Deploying!
Posted on February 1, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.