This project is a simple web application built using Flask, React, and PostgreSQL. It allows users to retrieve product information and perform basic operations like adding and deleting products from the database.
- Retrieve product information from the database
- Add new products to the database
- Delete existing products from the database
The following explains the usage of each directory:
backend:including the source code to create the api serverfrontend: including the source code to create the frontend pagekubernetes: including the manifests used to deploypostgres,flaskandwebon GKErest-api-chart: including the herm charts
Our project is shown on GKE
-
First, building Docker Images and publishing to a registry:
cd backend(from root directory)Show the dockerfile
cat Dockerfiledocker build -t mjajod2/flask:v10 .docker push mjajod2/flask:v10Then, we build and push the web frontend images to registry:
cd frontend(from root directory)docker build -t mjajod2/web-frontend:vs2docker push mjajod2/web-frontend:vs2 -
Deploying the application on GKE
Setting Postgres config:
kubectl apply -f ./kubernetes/postgres/postgres-config.yamlCreating the database credentials:
kubectl apply -f ./kubernetes/postgres/postgres-secret.yamlCreating the volume:
kubectl apply -f ./kubernetes/postgres/postgres-storage.yamlCreating the deployment, service and network policy for the postgres:
kubectl apply -f ./kubernetes/postgres/postgres-deployment.yamlkubectl apply -f ./kubernetes/postgres/postgres-service.yamlCheck the pods now:
kubectl get podsCreating the Flask deployment and service:
kubectl apply -f ./kubernetes/flask/api-deployment.yaml kubectl apply -f ./kubernetes/flask/api-service.yamlCheck the pods now:
kubectl get podsCreating web-frontend deployment and service:
kubectl apply -f ./kubernetes/web/web-deployment.yamlkubectl apply -f ./kubernetes/web/web-ingress.yamlkubectl apply -f ./kubernetes/web/web-service.yamlCheck the pods now:
kubectl get pods -
Scaling the stateless application:
kubectl scale --replicas=3 deployment web-frontend-deployment: Scales the web-frontend from 1 to 3 replicas.kubectl get pods: To check the scaling results -
Pre-requisites configuration:
kubectl get storageclass: Shows the storage class (Can also be seen usingkubectl get pv). -
Deployment Rollout:
For deployment rollout:
kubectl edit deployment/web-frontend-deployment:Update
terminationGracePeriodSecondsto 60.The output is similar to
deployment.apps/web-frontend edited.To see the rollout status:
kubectl rollout status deployment/web-frontend-deploymentThe deployment rollout can be checked by seeing the new pods created using:
kubectl get podscd canaryDelete the web deployment
kubectl delete deployment web-frontend-deploymentkubectl apply -f web-d1.yamlkubectl get pods --show-labelskubectl apply -f web-d2.yamlkubectl scale --replicas=9 deploy web-frontend-deploymentkubectl get pods --show-labelskubectl scale --replicas=9 deploy web-frontend-deployment-2kubectl delete deploy web-frontend-deploymentkubectl get pods --show-labels -
cd roles/pod-role-configkubectl apply -f .kubectl get roles: Shows the roles.This role can reach pods:
kubectl get pods --as=system:serviceaccount:default:serviceaccount-1This role cannot reach secrets
kubectl get secrets --as=system:serviceaccount:default:serviceaccount-1 -
Show network policy:
kubectl get networkpolicies -
Install, Upgrade and Uninstall the application using Helm
cd helmShow the Charts andcd../../../../Packages the helm chart
helm package web-frontend-chartInstalls the application.
helm install demo ./web-frontend-chart-1.0.0.tgzUpgrade the version:
Change the version number to
2.0.0:sudo nano web-frontend-chart/Chart.yamlPackages the helm chart again:
helm package web-frontend-chartTo show the current chart version:
helm lsUpgrades the application to 2.0.0:
helm upgrade demo ./web-frontend-chart-2.0.0.tgzTo show the upgraded 2.0.0 version:
helm lsTo uninstall the application:
helm uninstall demoTo show the application has been uninstalled:
helm ls