flask-vue-kubernetesFlask + Vue + Postgres + Docker + Kubernetes
Running Flask on Kubernetes
Want to learn how to build this?
Check out the post.
Want to use this project?
Docker
Build the images and spin up the containers:
$ docker-compose up -d --buildRun the migrations and seed the database:
$ docker-compose exec server python manage.py recreate_db
$ docker-compose exec server python manage.py seed_dbTest it out at:
Kubernetes
Minikube
Install and run Minikube:
- Install a Hypervisor (like VirtualBox or HyperKit) to manage virtual machines
- Install and Set Up kubectl to deploy and manage apps on Kubernetes
- Install Minikube
Start the cluster:
$ minikube start --vm-driver=virtualbox
$ minikube dashboardVolume
Create the volume:
$ kubectl apply -f ./kubernetes/persistent-volume.ymlCreate the volume claim:
$ kubectl apply -f ./kubernetes/persistent-volume-claim.ymlSecrets
Create the secret object:
$ kubectl apply -f ./kubernetes/secret.ymlPostgres
Create deployment:
$ kubectl create -f ./kubernetes/postgres-deployment.ymlCreate the service:
$ kubectl create -f ./kubernetes/postgres-service.ymlCreate the database:
$ kubectl get pods
$ kubectl exec postgres-<POD_IDENTIFIER> --stdin --tty -- createdb -U postgres booksFlask
Build and push the image to Docker Hub:
$ docker build -t mjhea0/flask-kubernetes ./services/server
$ docker push mjhea0/flask-kubernetes
Make sure to replace
mjhea0with your Docker Hub namespace in the above commands as well as in kubernetes/flask-deployment.yml
Create the deployment:
$ kubectl create -f ./kubernetes/flask-deployment.ymlCreate the service:
$ kubectl create -f ./kubernetes/flask-service.ymlApply the migrations and seed the database:
$ kubectl get pods
$ kubectl exec flask-<POD_IDENTIFIER> --stdin --tty -- python manage.py recreate_db
$ kubectl exec flask-<POD_IDENTIFIER> --stdin --tty -- python manage.py seed_dbIngress
Enable and apply:
$ minikube addons enable ingress
$ kubectl apply -f ./kubernetes/minikube-ingress.ymlAdd entry to /etc/hosts file:
<MINIKUBE_IP> hello.world
Try it out:
Vue
Build and push the image to Docker Hub:
$ docker build -t mjhea0/vue-kubernetes ./services/client \
-f ./services/client/Dockerfile-minikube
$ docker push mjhea0/vue-kubernetes
Again, replace
mjhea0with your Docker Hub namespace in the above commands as well as in kubernetes/vue-deployment.yml
Create the deployment:
$ kubectl create -f ./kubernetes/vue-deployment.ymlCreate the service:
$ kubectl create -f ./kubernetes/vue-service.ymlTry it out at http://hello.world/.
