Kubernetes

Create a Kubernetes Deployment

The deployments for Kubernetes represent the tool that allows the Kubernetes to know how to modify or create the pod’s instances having the containerized applications. Deployments can run the scaled number of pod replicas, move back to the earlier deployments when necessary, and can also handle the rollout for an updated code.

Procedure

This article will show a practical demonstration of the method to create the deployment for Kubernetes. To work with Kubernetes, we first have to make sure that we have a platform where we can run Kubernetes. These platforms include: Google cloud platform, Linux/ Ubuntu, AWS, and etc. We may use any of the mentioned platforms to run Kubernetes successfully.

Example # 01

This example will show how we can create a deployment in Kubernetes. Before getting started with the Kubernetes deployment, we would first have to create a cluster since Kubernetes is an open-source platform that is used to manage and orchestrate the execution of the applications of the containers across multiple computer clusters. The cluster for Kubernetes has two different types of resources. Each resource has its function in the cluster and these are the “control plane” and the “nodes”. The control plane in the cluster works as a manager for the Kubernetes cluster.
This coordinates and manages every possible activity in the cluster from the scheduling of the applications, maintaining or about the desired state of the application, controlling the new update, and also to efficiently scale the applications.

The Kubernetes cluster has two nodes in it. The node in the cluster could be either a virtual machine or the computer in bare metal form (physical) and its functionality is to work as the machine works for the cluster. Every node has its kubelet and it communicates with the control plane of the Kubernetes cluster and also manages the node. So, the cluster’s function, whenever we deploy an application on Kubernetes, we indirectly tell the control plane in the Kubernetes cluster to start the containers. Then, the control plane makes the containers run on the nodes of the Kubernetes clusters.

These nodes then coordinate with the control plane through the API of Kubernetes which is exposed by the control panel. And these can also be used by the end user for the interaction with the Kubernetes cluster.

We can deploy the Kubernetes cluster either on physical computers or virtual machines. To start with Kubernetes, we can use the Kubernetes implementation platform “MiniKube” which enables the working of the virtual machine on our local systems and is available for any operating system like Windows, Mac, and Linux. It also provides bootstrapping operations such as start, status, delete, and stop. Now, let us create this cluster and create the first Kubernetes deployment on it.

For the deployment, we will be using the Minikube we have pre-installed the minikube in the systems. Now, to start working with it, we will first check if the minikube is working and is properly installed and to do this in the terminal window type the following command as follows:

$ minikube version

The result of the command will be:

Now, we will move ahead and will try to start the minikube without command as

$ minikube start

Following the above command, the minikube has now started a separate virtual machine and in that virtual machine, a Kubernetes cluster is now running. So, we have a running Kubernetes cluster in the terminal now. To look for or to know about the cluster information, we will use the “kubectl” command interface. For that, we will check if the kubectl is installed by typing the command “kubectl version”.

$ kubectl version

The kubectl is installed and configured. It also gives information about the client and the server. Now, we are running the Kubernetes cluster so we can know about its details by using the kubectl command as “kubectl cluster-info”.

$ kubectl cluster-info

Let us now check for the nodes of the Kubernetes cluster by using the command “kubectl get nodes “.

$ kubectl get nodes

The cluster has only one node and its status is ready which means that this node is now ready to accept the applications.

We will now create a deployment using the kubectl command line interface which deals with Kubernetes API and interacts with the Kubernetes cluster. When we create a new deployment, we have to specify the application’s image and the number of copies of the application, and this can be called and updated once we create a deployment. To create the new deployment to run on Kubernetes, use the command “Kubernetes create deployment”. And to this, specify the name for the deployment and also the image location for the application.

Now, we have deployed a new application and the above command has looked for the node on which the application can run which was only one in this case. Now, get the list of the deployments using the command “kubectl get deployments” and we will have the following output:

$ kubectl get deployments

We will view the application on the proxy host to develop a connection between the host and the Kubernetes cluster.

The proxy is running in the second terminal where the commands given in terminal 1 are executed and their result is shown in terminal 2 on the server: 8001.

The pod is the unit of execution for a Kubernetes application. So here, we will specify the pod name and access it through API.

Conclusion

This guide discusses the methods to create the deployment in Kubernetes. We have run the deployment on the Minikube Kubernetes implementation. We first learned to create a Kubernetes cluster and then using this cluster we created a deployment to run the specific application on Kubernetes.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content