Welcome to the Kubernetes Deployment Control tutorial.
The primary goal of this tutorial is to provide an understanding of how to control and manage deployments in Kubernetes. Deployments are a key concept in Kubernetes which allow you to define the desired state of your application and Kubernetes works to maintain that state.
By the end of this tutorial, you will have learned:
- What Kubernetes deployments are and why they are important
- Different strategies to update applications in Kubernetes
- How to control and manage deployments
A Kubernetes Deployment is a resource object in Kubernetes that provides declarative updates for Pods and ReplicaSets. You describe the desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate.
There are two strategies for updating deployments:
1. Rolling Update: This is the default strategy which gradually replaces old pods with new ones.
2. Recreate: This strategy kills all existing pods before new ones are created.
Here's an example of a Kubernetes Deployment. Save it as deployment.yaml
:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
This Deployment creates three nginx Pods.
Let's perform a rolling update to the new version of nginx, 1.16.1. You can do this by updating the image
field in the Deployment spec:
kubectl set image deployment/nginx-deployment nginx=nginx:1.16.1
In this tutorial, we've covered how to control and manage deployments in Kubernetes, including different strategies to update applications. We've learned that Deployments are a key concept in Kubernetes that allow you to define the desired state of your application, and Kubernetes works to maintain that state.
Solutions and explanations will be given in the following section.
You can create the Deployment using the following command:
bash
kubectl create deployment nginx --image=nginx:1.14.2 --replicas=2
You can update the Deployment using the following command:
bash
kubectl set image deployment/nginx nginx=nginx:1.16.1
You can scale the Deployment using the following command:
bash
kubectl scale deployment nginx --replicas=5
Now, you are ready to go forth and manage your own Deployments in Kubernetes! Enjoy the power of orchestration!