Kubernetes is one of the most popular container orchestration tool used widely. Its is used to manage different container engines like docker, containerd, cri-o, rkt, etc. Nginx is very light weight which can Improve the Performance, Reliability, and Security of Your Applications. Nginx is popularly used as load balancer replacing hardware load balancers.
We will deploy nginx on Kubernetes cluster running docker engine.
Prerequisites
To deploy nginx, you should have Kubernetes cluster up and running. We will be deploying nginx on Kubernetes cluster on below test environment.
Environment
192.168.2.128 master.onehalt.in master
192.168.2.129 node1.onehalt.in node1
192.168.2.130 node2.onehalt.in node2
Deploy nginx on Kubernetes cluster
We will first check the cluster status before deploying the nginx application.
Since all our nodes are in “Ready” state and working fine, we will now deploy the nginx applicaiton.
# kubectl create deployment nginx --image=nginx
Now lets check the deployment status of the nginx application using below command
# kubectl get deployments
As we can see, our nginx application has been successfully deployed, deployment nginx is ready and available. We can check the nginx deployment in detail using the below command. It will display various properties of the deployment like deployment name, number of Replicas, pod details, container,etc
# kubectl describe deployment nginx
Exposing nginx to Public
Now lets expose the nginx application so that we can access it from outside the kubernetes environment. We will create service for nginx and expose it on http port 80. We will verify the service status on the cluster.
# kubectl create service nodeport nginx --tcp=80:80
Thus we have created a service for exposing nginx on port 80. Let try to access the nginx service using curl.
# curl master.onehalt.in:30054
“Welcome to nginx” , Nginx has been deployed successfully.
Since we have exposed the nginx service publicly, nginx should be accessible from the Kubernetes host or if we have public IP address we can access the nginx application.
Conclusion
Hence, we have successfully deployed nginx on kubernetes and have expose the same using kubernetes service. We are also able to access the deployed nginx application. Refer Kubernetes official documentation to know more about Kubernetes.
Happy Learning😊