Deployment Exercise-01

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

i) Create a deployment YAML with Environment Variables.

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 3
selector:
matchLabels:
app: nginx-app
template:
metadata:
name: nginx-pod
labels:
app: nginx-app
spec:
containers:
- name: nginx-container
image: nginx:1.18
ports:
- 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

--

--

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