This guide will describe the set up and deployment of a typical Coding Task Challenge Hotel Manager using Minikube and Kubernetes. The setup includes both frontend and backend services, as well as the PostgreSQL database.
The application consists of:
- Frontend: A Next.js application for the user interface.
- Backend: A Flask API to manage hotel room data.
- PostgreSQL Database: Used to persist hotel room data.
Before deploying to Kubernetes, you need to build Docker images for the frontend and backend.
The following bash code defines the steps to build and run the Next.js application inside a Docker container:
cd hotel-manager-frontend
docker build -t hotel-manager-frontend .
The following bash code defines the steps to build and run the Flask API inside a Docker container:
cd hotel-manager
docker build -t hotel-manager .
Ensure you have Minikube installed. If not, follow the Minikube installation guide.
minikube start
This step skips uploading the images to a docker file host (such as DockerHub):
minikube image load hotel-manager:latest
minikube image load hotel-manager-frontend:latest
You need to apply the Kubernetes deployment configurations for each service. Having all YAML files are located in a k8s directory, you can apply them using the following commands.
- Defines the deployment and service for PostgreSQL, used to store hotel room data.
- Configures the database with user credentials and exposes it on port
5432
.
kubectl apply -f k8s/postgresql-deployment.yaml
- Deploys the Flask API and connects it to the PostgreSQL database via environment variables.
- Exposes the backend API on port
5000
.
kubectl apply -f k8s/backend-deployment.yaml
- Deploys the Next.js application and exposes it on port
3000
.
kubectl apply -f k8s/frontend-deployment.yaml
You can check the status of the pods and services in the Kubernetes cluster to ensure everything is running correctly.
kubectl get pods
kubectl get svc
Once the Frontend is running in the cluster, you need to expose it locally to access the application.
minikube service hotel-manager-frontend
This will open the frontend service in your default web browser.
Once you're done, you can delete the resources to clean up your Minikube environment.
kubectl delete -f k8s/
minikube stop