- Assuing you have installed MiniKube and Kubectl on your machine, you can start MiniKube by running the following command:
minikube start
minikube status
minikube dashboard
- Build Frontend Image in Minikube
eval $(minikube docker-env)
docker build -t 002_imagepro-frontend:latest --file Dockerfile_Frontend .
- Create a Deployment for Frontend
kubectl apply -f frontend_kube_deployment.yaml
kubectl apply -f frontend_kube_service.yaml
- Add ingress to minikube and verify the nginx controller is running
minikube addons enable ingress
minikube addons enable ingress-dns
kubectl get pods -n ingress-nginx
Note: If running on MacOS you will need to add the following to your /etc/hosts file to ensure ingress works locally
sudo nano /etc/hosts
Add the following line to the file
127.0.0.1 frontend.example.com
- Verify the frontend service is running
minikube service frontend-service --url
To visit the frontend open a new terminal and run
minikube tunnel
Then visit the url http://frontend.example.com.
- Build Backend Image in Minikube
eval $(minikube docker-env)
docker build -t 002_imagepro-backend:latest --file Dockerfile_Backend .
- Create a Deployment for Backend
kubectl apply -f backend_kube_deployment.yaml
kubectl apply -f backend_kube_service.yaml
- Create A Volume for Persistent Storage
kubectl apply -f postgres_kube_persistantvolume.yaml
kubectl apply -f postgres_kube_persistantvolume_service.yaml
kubectl apply -f postgres_kube_persistantvolume_statefulset.yaml
kubectl apply -f postgres_kube_persistantvolumeclaim.yaml
kubectl apply -f postgres_kube_secrets.yaml
- To restart all pods and services
kubectl delete all --all -n default
- Testing Frontend and Backend Connection
To ensure that the frontend and backend pods are connected, you can go to minikube dashboard and enter the frontend pod and run the following command in the exec shell:
curl -X POST "http://backend-service:8000/login" \
-H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
--data-urlencode "[email protected]" \
--data-urlencode "password=abcdefg" \
--cookie-jar cookie.txt \
--cookie cookie.txt \
--include
You should get a response with a 200 status code and an access token in it for a successful login If you go to the logs of the backend pod, you should see a successful POST /login request