Kubernetes is a powerful container orchestration platform that allows you to deploy, scale, and manage containerized applications with ease. In this blog, we will walk you through the steps to deploy a Todo app on Kubernetes. We will start by cloning the source code, containerize the application using Docker, push the Docker image to DockerHub, write Kubernetes manifest files, and finally deploy and expose the app on Kubernetes. Let's get started!
Once you have downloaded django, go to the cloned repo directory and run the following command
$ python manage.py makemigrations
This will create all the migrations file (database migrations) required to run this App.
Now, to apply this migrations run the following command
$ python manage.py migrate
One last step and then our todo App will be live. We need to create an admin user to run this App. On the terminal, type the following command and provide username, password and email for the admin user
$ python manage.py createsuperuser
That was pretty simple, right? Now let's make the App live. We…
TABLE OF CONTENTS Step 1: Clone the source code
Step 2: Containerize the Application using Docker
Step 3: Building Docker-Image
Step 4: Push the Image To DockerHub
Step 5: Write a Kubernetes Manifest File
Write Deployment.yml file
Write Service.yml file
Step 6: Deploy the app to Kubernetes and create a Service for it
Step 7: Expose the app
You have successfully Deployed a todo-app on Kubernetes.
Prerequisite for Deployment of a Todo-app on Kubernetes
Before we begin with the Project, we need to make sure we have the following prerequisites installed:
EC2 ( AMI- Ubuntu, Type- t2.micro )
EC2 ( AMI- Ubuntu, Type- t2.medium )
Docker
Minikube
kubectl
You can Install all this by doing the below steps one by one. and these steps are for Ubuntu AMI.
NOTE: In the t2.micro instance, only step one, Docker Installation, should be completed; in the t2.medium instance, both stages should be completed.
Step 1: Clone the Source Code
To begin, you'll need the source code of your Todo app. For this example, we'll assume you have a Git repository containing your app. Clone the repository to your local machine using the following command:
Copy code
git clone <repository_url>
cd <app_directory>
Step 2: Containerize the Application using Docker
Kubernetes works with containerized applications, so we need to containerize our Todo app using Docker. Create a Dockerfile in the root of your project directory with the following content:
FROM python:3
WORKDIR /data
RUN pip install django==3.2
COPY . .
RUN python manage.py migrate
EXPOSE 8000
CMD ["python","manage.py","runserver","0.0.0.0:8000"]
Step 3: Building Docker Image
Now it's time to build Docker Image from this Dockerfile. docker build -t <DockerHub_Username>/<Imagename> use this command to build a docker image.
Step 4: Push the Image To DockerHub
To deploy the app on Kubernetes, you need to make the Docker image accessible from a container registry like DockerHub. Push the image to DockerHub:
docker login
docker tag todo-app <your-dockerhub-username>/todo-app:v1
docker push <your-dockerhub-username>/todo-app:v1
Step 5: Write a Kubernetes Manifest File
To deploy an application on Kubernetes, you need to create YAML manifest files describing the desired state of your application. We'll create two files: Deployment.yml and Service.yml.