Kubernetes Integration with Python-CGI Web UI

M G GOVARDHAN GOWDA
4 min readSep 8, 2021

What is Kubernetes?

Kubernetes is a Greek for pilots or helmsman(the person holding the ship's steering wheel). Kubernetes abstracts away the hardware infrastructure and exposes your whole data center as a single enormous computational resource. It allows you to deploy and run your software components without having to know about the actual servers underneath. When deploying a multi-component application through Kubernetes, it selects a server for each component. deploys it and enables it to easily find and communicate with all the other components of your application.

Development and deployment of applications have changed in recent years, This change is both a consequence of splitting big monolithic apps into smaller microservices and of the changes in the infrastructure that runs those apps.

We will be Creating a web UI page as such that using normal English conversation your all commands can run in the background.
For example — when we write ‘run deployment using httpd image’ then it runs the complete deployment command in the backend.

Necessary Feature-
👉# It can launch pods with the specific names given by users.
👉#Run deployment using image and name given by the user.
👉#Expose services on given user input port number.
👉#Scale the replica according to user need.
👉#Delete complete environment created.
👉#Delete specific resources given by the user.
👉#Extra features related to k8s ( Optional)
Note — There should be a web UI-based menu display so that users can get to know what your web app can do.

This app will help the user to run all the Kubernetes commands:

In computing, Common Gateway Interface (CGI) is an interface that enables web servers to execute an external program(python program), typically to process user requests. Such programs are often written in a scripting language and are commonly referred to as CGI scripts, but they may include compiled programs.

When we are CGI, we don’t need to store HTML pages on a server but can be dynamically created as and when a user makes a website query.

httpd is the Apache HyperText Transfer Protocol (HTTP) server program. It is designed to be run as a standalone daemon process. When used like this it will create a pool of child processes or threads to handle requests.

Before running the server we need to install it in the OS(I am using RHEL 8)

# yum install httpd

Turn on the HTTP server

# systemctl start httpd

Your server is now live.

Now A CGI-bin is a folder used to house scripts that will interact with a Web browser to provide functionality for a Web page or website.

This is the default path generated of CGI-bin after installation of httpd. In this folder I have created a python folder docker.py and made it executable, That’s the reason it showing in the green color font.

chmod +x on a file (your script) only means that you’ll make it executable

Contents of Kube.py

#!/usr/bin/python3 
import cgi
import subprocess print("content-type: text/html")
print() f = cgi.FieldStorage()
cmd = f.getvalue("x")
output = subprocess.getoutput("sudo\t " + cmd)
print(output)

/var/www/html is just the default root folder of the Apache webserver. You can change that to be whatever folder you want by editing your apache.conf file (usually located in /etc/apache/conf) and changing the DocumentRoot attribute (see http://httpd.apache.org/docs/current/mod/core.html#documentroot for info on that)

/var/www/html being the folder you want to install your website on

Now turn off your system firewall (Terminal commands)

Now restart your server (Terminal commands)

To allow access to the webserver (terminal)

INSIDE /etc/sudoers add this line to allow access to the webserver(vim editor)

After All this, you are good to go and run Kubernetes commands on your Website.

Thanks for Reading !!

Keep Learning !! Keep Sharing !!

--

--

M G GOVARDHAN GOWDA

MLOPS internship trainee @LinuxWorld informatics Pvt. LTD. || Student @Dayananda Sagar University |