Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Deploy Nginx on a Kubernetes Cluster - DesignLinux

May 29 2020
designlinux 0 Comments

In our last article, we have discussed how to set up and run a Kubernetes Cluster, let’s discuss how we can deploy NGINX service on our cluster.

I will run this deployment on a Virtual Machine Hosted by a public cloud provider. As it is with many public cloud services, many generally maintain a public and private IP scheme for their Virtual Machines.

Testing Environment

Master Node - Public IP: 104.197.170.99 and Private IP: 10.128.15.195
Worker Node 1 - Public IP: 34.67.149.37 and Private IP: 10.128.15.196
Worker Node 2 - Public IP: 35.232.161.178 and Private IP: 10.128.15.197

Deploying NGINX on a Kubernetes Cluster

We will run this deployment from the master-node.

Let’s begin by checking the status of the cluster. All your nodes should be in a READY state.

# kubectl get nodes
Check Kubernetes Cluster Status

Check Kubernetes Cluster Status

We create a deployment of NGINX using the NGINX image.

# kubectl create deployment nginx --image=nginx
Deploying Nginx on Kubernetes

Deploying Nginx on Kubernetes

You can now see the state of your deployment.

# kubectl get deployments
Check Deployment of Nginx on Kubernetes

Check Deployment of Nginx on Kubernetes

If you’d like to see more detail about your deployment, you can run the describe command. For example, it is possible to determine how many replicas of the deployment are running. In our case, we expect to see a replica of 1 running (i.e 1/1 replicas).

# kubectl describe deployment nginx
Check Nginx Deployment Details

Check Nginx Deployment Details

Now your Nginx deployment is active, you may want to expose the NGINX service to a public IP reachable on the internet.

Exposing Your Nginx Service to Public Network

Kubernetes offers several options when exposing your service based on a feature called Kubernetes Service-types and they are:

  1. ClusterIP – This Service-type generally exposes the service on an internal IP, reachable only within the cluster, and possibly only within the cluster-nodes.
  2. NodePort – This is the most basic option of exposing your service to be accessible outside of your cluster, on a specific port (called the NodePort) on every node in the cluster. We will illustrate this option shortly.
  3. LoadBalancer – This option leverages on external Load-Balancing services offered by various providers to allow access to your service. This is a more reliable option when thinking about high availability for your service, and has more feature beyond default access.
  4. ExternalName – This service does traffic redirect to services outside of the cluster. As such the service is thus mapped to a DNS name that could be hosted out of your cluster. It is important to note that this does not use proxying.

The default Service-type is ClusterIP.

In our scenario, we want to use the NodePort Service-type because we have both a public and private IP address and we do not need an external load balancer for now. With this service-type, Kubernetes will assign this service on ports on the 30000+ range.

# kubectl create service nodeport nginx --tcp=80:80
Create NodePort Service to Expose Nginx

Create NodePort Service to Expose Nginx

Run the get svc command to see a summary of the service and the ports exposed.

# kubectl get svc
Check Nginx Service and Port

Check Nginx Service and Port

Now you can verify that the Nginx page is reachable on all nodes using the curl command.

# curl master-node:30386
# curl node-1:30386
# curl node-2:30386
Check Nginx Page on Kubernetes Cluster

Check Nginx Page on Kubernetes Cluster

As you can see, the “WELCOME TO NGINX!” page can be reached.

Reaching Ephemeral PUBLIC IP Addresses

As you may have noticed, Kubernetes reports that I have no active Public IP registered, or rather no EXTERNAL-IP registered.

# kubectl get svc
Check Nginx Service and Port

Check Nginx Service and Port

Let’s verify if it is indeed true, that I have no EXTERNAL IP attached to my interfaces using IP command.

# ip a
Check IP Addresses

Check IP Addresses

No public IP as you can see.

As mentioned earlier, I am currently running this deployment on a Virtual Machine offered by a public cloud provider. So, while there’s no particular interface assigned a public IP, the VM provider has issued an Ephemeral external IP address.

An ephemeral external IP address is a temporary IP address that remains attached to the VM until the virtual instance is stopped. When the virtual instance is restarted, a new external IP is assigned. Basically put, it’s a simple way for service providers to leverage on idle public IPs.

The challenge here, other than the fact that your public IP is not static, is that the Ephemeral Public IP is simply an extension (or proxy) of the Private IP, and for that reason, the service will only be accessed on port 30386. That means that the service will be accessed on the URL <PublicIP:InternalPort>, that is 104.197.170.99:30386, which if you check your browser, you should be able to see the welcome page.

Check Nginx Page Deployed on Kubernetes

Check Nginx Page Deployed on Kubernetes

With that, we have successfully deployed NGINX on our 3-node Kubernetes cluster.

Sharing is Caring…
Share on FacebookShare on TwitterShare on LinkedinShare on Reddit

Related

Tags: Kubernetes Tips

How to Install Skype on Arch Linux

Prev Post

How To Install Pandora FMS Monitoring Tool in Ubuntu 18.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 687
  • 615,059

DesignLinux.com © All rights reserved

Go to mobile version