Overview:
A crucial step in deploying any application in Kubernetes is preparing a Docker image for your application and ensuring that it is stored in a remote Docker registry (such as Docker Hub).
This Docker image serves as the application’s packaged environment, and Kubernetes uses this image to run your application in containers across the cluster.
Without a correctly built and remotely stored Docker image, the deployment process cannot proceed.
Requirements
- Docker
- Docker Hub Account: Create a Docker Hub account if you don't have one. This will be used to push the Docker image to a public or private repository. https://www.docker.com/products/docker-hub/
Artifacts:
For the purpose of this tutorial we will be using this artifacts repository: https://gitlab.portaone.com:8949/read-only/tutorial-for-simple-application
Documentation Variables:
The documentation contains custom variables:
- <application_name>
- <application_version>
- <personal dockerhub repository>
For details related to variables meaning, please refer => Guide to deploy application in Add-On Mart for third-party developers
Instructions:
1. Build the Docker Image
In order to deploy your application to Kubernetes, a Docker image needs to be prepared locally.
The image packages the application and its environment, and this image will later be pushed to a remote registry for Kubernetes to use during the deployment process.
You can simplify the process by using the previously prepared docker-compose.yml
file.
Download repository → Artifacts
Simply substitute <application_name>
and <application_version>
in the file and use Docker Compose to build the application.
docker compose build
2. Push the Docker Image to Docker Hub
Once the Docker image is built locally, the next step is to push it to Docker Hub (or another Docker registry).
This makes the image accessible for Kubernetes to pull during the deployment process.
2.1 Login to Docker Hub:
docker login
2.2 Tag the Image for Docker Hub:
docker tag <application_name>:<application_version> <personal dockerhub repository_name>/<application_name>:<application_version>
Explanation:
<personal dockerhub repository>/<application_name>:<application_version>
: Re-tags the image with your Docker Hub username (replace<personal dockerhub repository>
with your actual username).
2.3 Push the Image to Docker Hub:
docker push <personal dockerhub repository>/<application_name>:<application_version>
2.4 Verify the Image on Docker Hub:
Check that the image is available in your Docker Hub repository by visiting your Docker Hub account and verifying the image is listed.
Summary
By following these instructions, a Docker image has been successfully created for the FastAPI application and pushed to Docker Hub. This image will be used in subsequent steps for deploying the application in a Kubernetes cluster.