Deployment Exercise-01

  • There are two basic ways to deploy to Kubernetes: imperatively, with the many kubectl commands, or declaratively, by writing YAML manifests.
  • It is good practice to use YAML for production.
  • kubectl commands for debugging in production or dev/test environment.

Let’s first create a simple Nginx deployment with three replicas.

i) Create a deployment YAML with Environment Variables.

apiVersion: apps/v1
kind: Deployment
name: nginx-deploy
replicas: 3
app: nginx-app
name: nginx-pod
app: nginx-app
- name: nginx-container
image: nginx:1.18
- containerPort: 80

ii) Create the deployment using the following command.

$ kubectl apply -f nginx-deploy.yaml or 
$ kubectl create -f nginx-deploy.yaml

iii) we can see the Pods, replicas, and deployment in a single command.

$ kubectl get pods,rs,deployment

All objects are part of a deployment that we have created above.

iv) Creating Deployment “Imperatively” (from the command line):

$ kubectl create deployment NAME --image=[IMAGE-NAME] --replicas=[NUMBER]

v) Check the deployment created.

vi) We can check the deployment YAML file with — the dry-run option command print the YAML file in the command line.

$ kubectl create deployment redis-deploy --image=redis --replicas=3 --dry-run=client -o yaml

— dry-run option actually will not create deployment but he will help to understand the YAML.

vii) Instead of printing the YAML file in the command line we can save the YAML deployment file with any file.

$ kubectl create deployment redis-deploy — image=redis — replicas=3 — dry-run=client -o yaml > redis-deploy.yaml

viii) Displaying the YAML with different commands.

$ kubectl get deploy <NAME>
$ kubectl get deploy <NAME> -o wide
$ kubectl get deploy <NAME> -o yaml

ix) Get the details of the deployment

$ kubectl describe deploy <NAME>

x) Print Details of Pod Created by this Deployment

$ kubectl get pods — show-labels
$ kubectl get pods -l [LABEL]

xi) Scaling Applications — Update the replica count to 5

$ kubectl scale deploy [DEPLOYMENT-NAME] — replicas=[COUNT]

xii) Edit the Deployment, change the nginx image from nginx:1.18 to nginx:latest

$ kubectl edit deploy [DEPLOYMENT-NAME]

Run the above edit command search for the image and change the version.

xiii) Running operations directly with the YAML file

SYNTAX: kubectl [OPERATION] –f [FILE-NAME.yaml]

$ kubectl get –f [FILE-NAME.yaml]
$ kubectl describe –f [FILE-NAME.yaml]
$ kubectl edit –f [FILE-NAME.yaml]
$ kubectl delete –f [FILE-NAME.yaml]
$ kubectl create –f [FILE-NAME.yaml]
$ kubectl describe –f [FILE-NAME.yaml]
kubectl edit –f [FILE-NAME.yaml]
$ kubectl delete –f [FILE-NAME.yaml]
$ kubectl create –f [FILE-NAME.yaml]

xiv) Deleting the deployment, will delete the pods, replicaSet that belong to deployment, let’s check.

$ kubectl delete deploy <NAME>
$ kubectl get deploy
$ kubectl get rs
$ kubectl get pods




DevOps Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Backup Config Cisco to Macbook

How to open figure palette in MatLab?

Loops in Java…

Integrating HMS Kits in Health Care Shopping Application

Coding Our First Django App

Writing your first Django app part 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


DevOps Engineer

More from Medium

ReplicaSet Exercise-01

Learn Kubernetes: Creation of a pod running a Nginx server

Getting Started With Kubernetes

Helm Chart For Creating and Publishing Jenkins on