Kubernetes Integration with Python-CGI

Task Description

Pramod Kumar Gupta
5 min readSep 8, 2021

--

Create webUI page as such that using normal English conversation your all commands can run in background.

Example — when we write ‘run deployment using httpd image’ then it run complete deployment command in backend.

Feature necessary -

👉 It can launch pods with specific name given by user.

👉 Run deployment using image and name given by 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 user.

👉 Extra features related to k8s ( Optional)

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

Let’s Start.

First we need to install minkube for our kubernetes cluster

Follow this link to download minikube :

https://kubernetes.io/docs/tasks/tools/install-minikube/

After downloading install it.

Follow this link to install kubectl on your system -

Install and Set Up kubectl on Windows | Kubernetes

After that start minikube by -

start minikube — driver=virtualbox

Now we will configure Linux OS to use minikube kube cluster.

Now ,

Login to Minikube VM.

User Name: docker

Password: tcuser

Now we will copy admin.conf file . We change the permissions of admin.conf file so that we can copy this file from here to Windows Machine. And afterwards we need to transfer this file to RHEL8 VM.

Now using winscp we will transfer the files

Launch the RHEL8 VM. Check the IP Address of system and again using WinSCP we can transfer admin.conf file from Windows to here i.e RHEL8 VM.

Now, we need kubectl software which acts as a client for k8s cluster. Copy below code in terminal and it will create a Kubernetes repo from which we can install kubectl.

https://kubernetes.io/docs/setup/productionenvironment/tools/kubeadm/install-kubeadm/

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg exclude=kubelet kubeadm kubectl EOF

To install kubectl:

yum install kubectl

Now, we have to make a small change inside admin.conf file. Bydefault it has the hostname written as the server. So, we need to replace it by the IP Address of the Minikube VM.

Now, close the VM and change the Network Adapter of VM.

Put 1st Adapter as NAT and 2nd Adapter as Host Only

Start the VM. Create a working directory and put the admin.conf file in that directory. I am moving it to var/www/cgi-bin because there cgi code will run to access kubernetes cluster

And we can run kubectl commands by appending — kubeconfig admin.conf at last of the command.

Example:

kubectl create deployment web-test — image=httpd — kubeconfig admin.conf

Now I have created a web ui and and python cgi code for accesing the kubernetes cluster.

Code link :

https://github.com/Pramod123789/Kubernetes-Integration-with-Python-cgi.git

Enter in search bar :

run pods and click on run pods

Provide the image name

then give the pod name

Same way you can run all functions.

Thanks for reading ……..

--

--