Kubernetes - Creating an App
Last Updated :
17 Mar, 2023
Pre-requisite: Kubernetes
In this article, we will discuss how to create a simple application on Kubernetes. Kubernetes is an open-source container orchestration system that helps to manage, deploy and scale containerized applications. Kubernetes provides a platform for automating the deployment, scaling, and operations of application containers across clusters of hosts.
Steps to Create an App
Here, we will create a simple Flask web application, containerize it, and deploy it on Kubernetes.
Step 1: Install Docker and Kubernetes. Firstly, we need to install Containers and Kubernetes. You can download and install Containers and Kubernetes from their official websites.
Step 2: Write the Flask Application. Create a new directory and navigate into it. Create a new Python file called app.py and write the following code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')
Step 3: Create a Dockerfile. Create a new file called Dockerfile in the same directory and write the following code:(in your BASH)
FROM python:3.7-alpine
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "app.py"]
Step 4: Build the Docker image using the following command:
docker build -t flask-app:v1 .
Then, run the Docker image using the following command:
docker run -p 5000:5000 flask-app:v1
Visit http://localhost:5000/ in your web browser to ensure that the app is running.
Step 5: Create a Kubernetes Deployment. Create a new file called deployment.yaml and write the following code:
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app-deployment
labels:
app: flask-app
spec:
replicas: 1
selector:
matchLabels:
app: flask-app
template:
metadata:
labels:
app: flask-app
spec:
containers:
- name: flask-app-container
image: flask-app:v1
ports:
- containerPort: 5000
Create the deployment using the following command:
kubectl apply -f deployment.yaml
Check the status of the deployment using the following command:
kubectl get deployments
Step 6: Create a Kubernetes Service. Create a new file called to service.yaml and write the following code:
apiVersion: v1
kind: Service
metadata:
name: flask-app-service
spec:
selector:
app: flask-app
ports:
- name: http
protocol: TCP
port: 80
targetPort: 5000
type: LoadBalancer
Create the service using the following command:
kubectl apply -f service.yaml
Check the status of the service using the following command:
kubectl get services
Step 7: Access the App Now, you can access the app by visiting the external IP of the service in your web browser.
Similar Reads
Kubernetes - Creating a ReplicaSet
Pre-requisite: Kubernetes A ReplicaSet is a key component of a Kubernetes application. It is a controller that ensures that a specified number of pod replicas are running at any given time. It is used to automatically replace any pods that fail, get deleted, or are terminated, ensuring the desired n
9 min read
Kubernetes - Autoscaling
The Main point of the cloud and Kubernetes is the ability to scale in the way that we can be able to add new nodes if the existing ones get full and at the same if the demand drops we should be able to delete those nodes. To solve this problem we can use Kubernetes auto scaler which is a component t
14 min read
Kubernetes - Kubectl Create and Kubectl Apply
Kubernetes is an open-source Container Orchestrating software platform that is widely used in modern application deployment and management. It comes up with many internal resources to manage the other working nodes Organizing as a Cluster facilitates seamless automatic scaling, and deployment update
8 min read
How to Deploy Angular App in Kubernetes ?
In the modern world of web development, Angular has become one of the most popular frameworks for building dynamic and responsive web applications. As the demand for scalability and reliability increases, deploying these applications in a containerized environment using Kubernetes has become a commo
5 min read
Kubernetes - Injecting ConfigMap as Files
Pre-requisite:- Kubernetes The automated deployment, scaling, and administration of software using a system called Kubernetes, an open-source container orchestration tool. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computin
3 min read
Deploying a React Application in Kubernetes
Kubernetes is an open-source free manager for your computer program. These programs can be in the containers. Each container holds a program and everything it needs to run. To Keep track of all these containers that contain your application this is where the Kubernetes role comes in. Kubernetes does
5 min read
Kubernetes - Creating Multiple Container in a Pod
Pre-requisite:- Kubernetes Kubernetes is a container management tool and it automates container deployment, load balancing, and container scaling. It is open-source and developed by Google in 2014 and written in Golang. All cloud providers adopt Kubernetes. It is scheduled runs and manages isolated
3 min read
Deploying A Node.js Application In kubernetes
Kubernetes, or K8s, is an open-sourced container orchestration technology that is used to automate the manual processes of deploying, managing, and scaling applications with the help of containers. Kubernetes was originally developed by engineers at Google, and In 2015, it was donated to CNCF (Cloud
9 min read
Kubernetes - Injecting ConfigMap in Pods
Pre-requisite: Kubernetes Leveraging the open-source container orchestration engine Kubernetes to automate the deployment, scalability, and management of applications. Another name for Kubernetes is K8s. Google originally created Kubernetes, which is currently overseen by the Cloud Native Computing
3 min read
Kubernetes - Create ConfigMap From YAML File
A ConfigMap is a dictionary consisting of non-confidential data. Its primary role is to keep the configuration separate from the container image. ConfigMap can be created in different ways. This article will cover the declarative approach to creating ConfigMap from the YAML file. Example: apiVersion
1 min read