How to deploy an application on Kubernetes cluster3 min read


Table of Contents
Introduction
Kubernetes is a container orchestration tool that is mainly used to deploy, scale, and manage a computer application on a multi-node cluster. In most of the scenarios, Docker is used as a containerization tool to work along with Kubernetes. A Kubernetes cluster means nothing but a master-worker setup of either on-premise machines or cloud instances that runs Kubernetes in it. There can be multiple master machines and multiple worker machines in a Kubernetes cluster. In our previous articles, we discussed how to install and set up a Kubernetes cluster (Ubuntu, CentOS). Now, let us understand how to deploy an application/service on a Kubernetes cluster.
We have used Nginx service here. Follow the below steps to deploy it.
Deploy an application on the Kubernetes cluster
1. First, we will have to create a yaml file. Execute the below command in the Master node,
sudo nano deploy.yml
2. Paste the below lines in the file,
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 5 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
The above file is to create a Nginx service with 5 replicas. You can change/remove the replicas parameter.
Make sure the indentation is as shown in the below screenshot,


Save and exit the file.
3. Now execute the below command to create the deployment,
kubectl apply -f deploy.yml


4. The Nginx service is now deployed. Execute the below command to check the deployments,
kubectl get deployments


5. Execute the below command to display the information about the deployment,
kubectl describe deployment nginx


6. We need to create a service for our application so that it can be accessed on the browser. Execute the below command to create a service,
kubectl create service nodeport nginx --tcp=80:80


7. Execute the below command to display the services,
kubectl get svc


8. You can see from the above screenshot that our Nginx service is created. Now we can access the application on the browser with the public IP address of the Worker node and the node port.


Done. We have successfully deployed an application on the Kubernetes cluster.
If you would like to deploy an application on a Docker container, refer to our article: Deploy war file on Tomcat Docker container.