To get started with Kubernetes, visit my blog Minikube - Launch First Kubernetes Cluster and Pod
What is deployment in k8s?
A Deployment provides a configuration for updates for Pods and replica sets.
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.
Getting Started
YAML file
To begin with, create a deployment.yml file and write yaml code as below for a to-do application.
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-app
labels:
app: todo
spec:
replicas: 2
selector:
matchLabels:
app: todo
template:
metadata:
labels:
app: todo
spec:
containers:
- name: todo
image: rishikeshops/todo-app
ports:
- containerPort: 3000
The configurations are for creating 2 replicas of the todo app. Image is from docker hub, container port assigned on 3000 and added to "todo" label.
Start minikube
Secondly, start the minikube:
minikube start
Create Deployment
Then after, give the below command in the terminal:
kubectl apply -f deployment.yml
It will create deployments.
Verify with the below command:
kubectl get deployments
It will show two replicas.
Modify deployment
Now, modify the file and change the replicas to 5.
Apply the changes:
kubectl apply -f deployment.yml
It will update the configuration and create 3 more Pods.
Conclusion
To sum up, We learned how to create yaml file for deployments and commands to run it. Deploying pods and modifying them are difficult tasks, however, we can overcome them through practice, practice and practice.