Applying and Managing Deployments
Applying Deployments
To apply a Kubernetes Deployment, you can use the kubectl apply
command and provide the Deployment specification file:
kubectl apply -f deployment.yaml
This will create the Deployment in your Kubernetes cluster based on the configuration defined in the deployment.yaml
file.
Monitoring Deployments
You can use the kubectl get
command to view the status of your Deployments:
kubectl get deployments
This will show you the current state of your Deployments, including the number of available and ready replicas.
You can also use the kubectl describe
command to get more detailed information about a specific Deployment:
kubectl describe deployment my-app
This will provide information about the Deployment, such as the container image, the update strategy, and the current state of the pods.
Updating Deployments
To update a Deployment, you can modify the Deployment specification and apply the changes. For example, to update the container image:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:v2
ports:
- containerPort: 80
Then, apply the updated Deployment specification:
kubectl apply -f deployment.yaml
Kubernetes will then perform a rolling update, replacing the old pods with the new ones based on the update strategy configured in the Deployment.
Rollbacks
If a Deployment update introduces issues, you can perform a rollback to a previous version of the Deployment. Kubernetes maintains a revision history of your Deployments, which allows you to easily roll back to a previous version.
To roll back a Deployment, you can use the kubectl rollout
command:
kubectl rollout undo deployment my-app
This will revert the Deployment to the previous revision, restoring the application to a working state.
By understanding how to apply, monitor, update, and roll back Kubernetes Deployments, you can effectively manage the lifecycle of your containerized applications.