KUBERNETES DEPLOYMENT

Khemnath chauhan
2 min readMar 6, 2022

--

As we dive into kubernetes deployment object. We need to know about kubernetes controller.

A Controller is a control loop that continuously watches the Kubernetes API and tries to manage the desired state of certain aspects of the cluster. There are a number of controllers- Deployments, ReplicaSets and Jobs.

Deployments

A Deployment has the ability to keep a defined number of replica Pods up and running. A Deployment can also update those Pods to resemble the desired state by means of rolling updates. For example, if you wanted to update a container image to a newer version, you would create a Deployment, and the controller would update the container images one by one until the desired state is achieved. This ensures that there is no downtime when updating or altering your Pods.

Sample deployment yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: webserver
spec:
replicas: 3
selector:
matchLabels:
app: web1
template:
metadata:
labels:
app: web1
spec:
containers:
- name: nginx-container
image: nginx:1.21.6

To check how deployment creates Replicasets & PODS.

$ kubectl describe deployment nginx-deployment

To Check the ReplicaSets create:

$ kubectl get rs

To scale up or down replicas ( number of pods).

$ kubectl scale --replicas=2 deploy nginx-deployment

To check what’s running inside container.

$ kubectl log -f <podName>

Other important deployment related commands:

# To check out rollout status
$kubectl rollout status deployment nginx-deployment
# Check all revision history
$kubectl rollout history deployment nginx-deployment
# To Rollback to previous version
$kubectl rollout undo deploy/nginx-deployment
# To Rollback to specific version
$kubectl rollout undo deploy/nginx-deployment --to-revision=<<version>>

--

--

Khemnath chauhan
Khemnath chauhan

No responses yet