Comprehensive Guide to Kubernetes Deployment
Kubernetes Deployment Controller Object
Create Replicas of Pod and deploy the Pod instances to the Worker Nodes
Here, the Replicas are created using ReplicaSet
Used to Deploy the Replicas of Pods in the available WorkerNodes
Perform Scale-Up and Scale-Down the Pod Instances
Perform Upgrade and Downgrade the Pod Versions without any downtime.
Deployment Strategy called - Rolling Update Strategy to ensure Zero DownTime during Upgrade/Downgrade.
Creates :
Deployment Controller
Replicaset
Pod Instances
Replicaset Controller Object
Used to Create Replicas/Copies of pods
Replicaset Created Automatically during the Deployment Object Creation
Let's see how deployment works.
Deployment YAML file
# nginx-deploy.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy labels: app: nginx-deploy-lbl spec: replicas: 3 template: metadata: labels: app: nginx-app spec: containers: - name: nginx-container image: nginx:stable-otel ports: - containerPort: 80 selector: matchLabels: app: nginx-app
Create and Display Deployment
kubectl create -f nginx-deploy.yaml kubectl get deploy -l app=nginx-app kubectl get rs -l app=nginx-app kubectl get po -l app=nginx-app kubectl describe deploy nginx-deploy
Testing: Rollback update
kubectl set image deploy nginx-deploy nginx-container=nginx:stable-pearl kubectl rollout status deployment/nginx-deploy kubectl rollout undo deployment/nginx-deploy kubectl rollout status deployment/nginx-deploy kubectl describe deploy nginx-deploy | grep -i image
When wrong image version mentioned, then “ImagePullBackOff” Error is shown
Testing: Update Version of "nginx:stable-otel" to "nginx:stable-perl"
kubectl set image deploy nginx-deploy nginx-container=nginx:stable-perl # or kubectl edit deploy nginx-deploy kubectl rollout status deployment/nginx-deploy kubectl get deploy
Testing: Scale UP
kubectl scale deployment nginx-deploy --replicas=5 kubectl get deploy kubectl get po -o wide
Testing: Scale DOWN
kubectl scale deployment nginx-deploy --replicas=3 kubectl get deploy kubectl get po -o wide
Cleanup
kubectl delete -f nginx-deploy.yaml kubectl get deploy kubectl get rs kubectl get po
Kubernetes services :
NodePort Service
Used to Expose the pod to Internet
It is a special type of service, which can assign addition port ranges from 30000 to 32767.
Map the deployment object to NodePort Service, it will be applicable to all corresponding pods.
Access it thru.
Open Web-browser and access webapage using
http://<external-nodeip>:<nodeport>