TEAM TASK 9
Team Task 9 Successfully completed — Kubernetes Integration with Python-CGI under the guidance of Vimal Daga sir!!🥳
Task Description 📄
📌 In continuation of task 7.1 you need to Integrate Kubernetes commands that can be run through webUI created by you.
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)
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers. A Pod’s contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific “logical host”: it contains one or more application containers which are relatively tightly coupled. In non-cloud contexts, applications executed on the same physical or virtual machine are analogous to cloud applications executed on the same logical host.
The objective of this section is to learn about application deployments, how it’s done with examples. We will deploy our app via the Kubectl CLI and configuration files.
To get the code follow the link given below :
Contribute to Abhimanyu45Gautam/Kubernetes_flask_webUI development by creating an account on GitHub.
Now that we have a running Kubernetes cluster, we can deploy a containerized application on it. This can be achieved through use of Deployment configurations. The deployments instruct Kubernetes how to create and update instances of your application. Once a deployment has been created, the kubernetes master schedules mentioned application instances into individual Nodes in the cluster.
Once the application has been created, Kubernetes deployment Controller will continuously monitor instances to ensure they satisfy the desired state. If a node hosting the application goes down or is deleted, the deployment controller replaces it, thus providing a self-healing mechanism to address machine failure or maintenance.
Deploying An App to Kubernetes
Kubernetes deployments can be managed via kubernetes command line interface kubectl. Kubectl uses the Kubernetes API to interact with the cluster. In this section we will look into some of the commands you will need to create deployments that run an application on the kubernetes cluster.
When creating a deployment you will need to specify the container image for your application and the number of replicas that you need in your cluster. This information can be changed later by updating the Deployment.
Create Nodejs Application
Now that we have established how we can manage deployments, let us create the application we will be deploying to our cluster. Create a folder in your workspace and add
Update the file with the following code. This will setup a simple server that we can use to test our deployments.
Let’s run our app to make sure it is working fine.
When you visit http://localhost:3000, you should be able to see “Hello, World” on your browser. Now that our app is working, let’s package it into a container.
Create a Docker container image
Before we can make any deployments to our cluster we need to create an image we will be using. This image will contain the app we just built. In your current working directory, create a file named
Dockerfile. A Dockerfile describes the image that you want to build. Images can be built by extending an existing image, for instance, our images will extend from Nodejs Image.
This image extends the official NodeJs image, exposes port 3000, copies
index.jsfile to the image and starts the NodeJs server.
Because we are using minikube, instead of pushing our images to a registry, we can simply build the image using the same docker host as the minikube VM so that the images will be available automatically. To achieve this we will have to ensure that we are using Minikube Docker Daemon:
If in any case, you don’t wish to use minikube host, you can undo this change by running.
Having setup docker let’s build our image.
The command above will build our image tagged
kubernetes-101:v1 using our Dockerfile. After the command is done executing, the image will be available within our minikube context.
Create a Kubernetes Deployment
Kubernetes deployments are responsible for creating and managing pods — a kubernetes pod is a group of one or more containers, tied together for the purpose of administration and networking. Deployments check on the health of the pods and restart the pods’ container when it terminates. For this reason, deployments are the recommended way to manage the creation and scaling of pods.
Kubernetes Deployments can be created in two ways, through kubectl run command or through YAML configuration- which is the recommended approach.
Note: We will be using the command line approach, however, we will be including the yaml configuration in code repository accompanying this article.
Run the command below to create a deployment.
This command will create a deployment that manages a pod. This pod will run a container based on the
kubernetes-101:v1image we created earlier on port 3000.
We can check if our deployment has been created by running kubectl get deployments command.
As you can see we now have a deployment with name
kubernetes-101. If we need more details on this deployment we can use the describe command.
This command provides more detailed information about our deployment this includes the image, replicas, ports, status etc. We can use this information to audit our deployments.
So far we have created the deployments via command-line. We can still achieve the same results using yaml configuration.
Note: If you didn’t clone the code repository accompanying add the following yaml configuration, add the following code snippet under the directory named k8s within your current working directory.
Before we proceed, let’s delete the previous deployment. Run the following command against the cluster.
After is done executing, run
kubectl create -f k8s/deployment.yaml
When you run the commands we did before, you will notice that we get the same details and information. Configuration files a more recommended approach to creating kubernetes objects. This approach embraces the concept of infrastructure as code with makes managing the cluster much easier.
Now that we have explored both approaches of creating deployments, let’s test if our deployment is actually working. We can achieve this by via kubernetes port forwarding.
First, we get the pod name, then use the kubectl port-forward command to forward traffic to the local port. We can now access our deployed application on