Deployments represent a set of multiple, identical Pods with no unique identities. Basically, a Deployment runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive. By so doing, they help ensure that one or more instances of your application are available to serve user requests.
Here at Outsource Path, as part of our Server Management Services, we regularly help our Customers to perform related AWS Kubernetes queries.
In this context, we shall look into how to create your first deployment on a Kubernetes Cluster using Nginx.
A Deployment provides declarative updates for Pods and ReplicaSets. The state in the Deployment and the Deployment Controller changes the actual state to the desired state at a controlled rate.
We can create and manage a Deployment by using the "kubectl" Kubernetes command line interface. Kubectl uses the Kubernetes API to interact with the cluster.
To create our first deployment let's just create a new directory to create our Object/Deployment File. Use the following command to create a new directory in your system:
$ mkdir my-first-deployment
$ cd my-first-deployment/
Before we proceed, verify the status of the cluster.
To check the Nodes available in the cluster and to check the version of the "kubectl" use the following commands:
$ sudo kubectl version
$ sudo kubectl get nodes
Once you have Nodes available in your cluster you are ready to create your deployment.
Create a file "my-first-deployment.yml" with the following block of code
$ vim my-first-deployment.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
Here,
Now you are ready to create your deployment using the following commands:
$ sudo kubectl apply -f my-first-deployment.yml
$ sudo kubectl get deployments
Here, you will see that the deployment has been created with two pods that are available to use.
You can get the details of the pods using the following command:
$ sudo kubectl get pods
If you want to know more about the deployment you can use this "kubectl describe" command to get the complete details of the deployment:
$ sudo kubectl get deployments
$ sudo kubectl describe deployments nginx-deployment
If you no more require the deployment you can delete it using "kubectl delete command":
$ sudo kubectl get deployments
$ sudo kubectl delete deployments nginx-deployment
$ sudo kubectl get deployments
Here, you will see that the deployment is no more available after it is deleted.
Once you delete the deployment the pods too get deleted.
You can check for the availability of the pods using the following command:
$ sudo kubectl get pods
Now, you can see that the pods have been deleted after deleting the deployment and are not available.