How to Create & Update & Scale & Delete Deployment with kubectl in Kubernetes

shape
shape
shape
shape
shape
shape
shape
shape
How to Create & Update & Scale & Delete Deployment with kubectl in Kubernetes

This article describes How to Create & Update & Scale & Delete Deployment with kubectl in Kubernetes.

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

The name Kubernetes originates from Greek, meaning helmsman or pilot. Google open-sourced the Kubernetes project in 2014.

Creating and exploring a nginx deployment
You can run an application by creating a Kubernetes Deployment object, and you can describe a Deployment in a YAML file.
For example, this YAML file describes a Deployment that runs the nginx:1.7.9 Docker image:

cat << EOF > nginx-deployment.yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF

ls *nginx* -al

Create a Deployment based on the YAML file:
kubectl apply -f nginx-deployment.yaml

Display information about the Deployment:
kubectl describe deployment nginx-deployment

List the pods created by the deployment:
kubectl get pods -l app=nginx -o wide
watch kubectl get pods -l app=nginx -o wide

Display information about a pod:
kubectl describe pod <pod-name>
kubectl describe pod nginx-deployment-54f57cf6bf-kptzh
kubectl describe pod nginx-deployment-54f57cf6bf-kptzh nginx-deployment-54f57cf6bf-qxdpr

Updating the deployment
You can update the deployment by applying a new YAML file. This YAML file specifies that the deployment should be updated to use nginx 1.8.
cat << EOF > nginx-deployment-update.yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.8 # Update the version of nginx from 1.7.9 to 1.8
ports:
- containerPort: 80
EOF

ls *nginx* -al

Apply the new YAML file:
kubectl apply -f nginx-deployment-update.yaml

Watch the deployment create pods with new names and delete the old pods:
watch -d kubectl get pods -l app=nginx -o wide
watch -b -c -d kubectl get pods -o wide -l app=nginx

Scaling the application by increasing the replica count
You can increase the number of pods in your Deployment by applying a new YAML file. This YAML file sets replicas to 4, which specifies that the Deployment should have four pods:
cat << EOF > nginx-deployment-scale.yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 5 # Update the replicas from 2 to 5
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.8
ports:
- containerPort: 80
EOF

Apply the new YAML file:
kubectl apply -f nginx-deployment-scale.yaml

Verify that the Deployment has four pods:
kubectl get pods -l app=nginx -o wide
watch kubectl get pods -l app=nginx -o wide

Deleting a deployment
Delete the deployment by name:
kubectl delete deployment nginx-deployment

Now you can find some examples in this video.

Please subscribe to support our channel.
To be aware of our new videos please subscribe our channel.

Visit our website https://sdk-it.com
Visit our youtube channel
Watch IT & Learn IT & Apply IT.

Enjoy!