Giter VIP home page Giter VIP logo

flask-vue-kubernetes's Introduction

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 --build

Run the migrations and seed the database:

$ docker-compose exec server python manage.py recreate_db
$ docker-compose exec server python manage.py seed_db

Test it out at:

  1. http://localhost:8080/
  2. http://localhost:5001/books/ping
  3. http://localhost:5001/books

Kubernetes

Minikube

Install and run Minikube:

  1. Install a Hypervisor (like VirtualBox or HyperKit) to manage virtual machines
  2. Install and Set Up kubectl to deploy and manage apps on Kubernetes
  3. Install Minikube

Start the cluster:

$ minikube start --vm-driver=virtualbox
$ minikube dashboard

Volume

Create the volume:

$ kubectl apply -f ./kubernetes/persistent-volume.yml

Create the volume claim:

$ kubectl apply -f ./kubernetes/persistent-volume-claim.yml

Secrets

Create the secret object:

$ kubectl apply -f ./kubernetes/secret.yml

Postgres

Create deployment:

$ kubectl create -f ./kubernetes/postgres-deployment.yml

Create the service:

$ kubectl create -f ./kubernetes/postgres-service.yml

Create the database:

$ kubectl get pods
$ kubectl exec postgres-<POD_IDENTIFIER> --stdin --tty -- createdb -U postgres books

Flask

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 mjhea0 with 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.yml

Create the service:

$ kubectl create -f ./kubernetes/flask-service.yml

Apply 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_db

Ingress

Enable and apply:

$ minikube addons enable ingress
$ kubectl apply -f ./kubernetes/minikube-ingress.yml

Add entry to /etc/hosts file:

<MINIKUBE_IP> hello.world

Try it out:

  1. http://hello.world/books/ping
  2. http://hello.world/books

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 mjhea0 with 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.yml

Create the service:

$ kubectl create -f ./kubernetes/vue-service.yml

Try it out at http://hello.world/.

flask-vue-kubernetes's People

Contributors

jinzishuai avatar maslo2017 avatar mjhea0 avatar mrhadenough avatar senorsmile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-vue-kubernetes's Issues

Postgres - error while creating mount source path

Hi,

I'm experiencing the following error:

Error: failed to start container "postgres": Error response from daemon: error while creating mount source path
 '/data/postgres-pv': mkdir /data: read-only file system

PersistentVolume and PersistentVolumeClaim are in place

Name Status Type Source Read only Storage Class Claim
postgres-pv BOUND Host path /data/postgres-pv False standard postgres-pvc

Pd. I'm using Google Cloud Kubernetes single node.

Add license

Hi,

Would you mind adding a license as I would like to use/modify your code for the purpose of a demo application for a faculty project ?

kubectl create -f postgres-deployment.yml

I just following your tutorial [https://testdriven.io/blog/running-flask-on-kubernetes/] but the 'kubectl create ...' command fails as follows:

error: unable to recognize "postgres-deployment.yml": no matches for kind "Deployment" in version "extensions/v1beta1"

I am running a k8s cluster deployed with files from this repository https://github.com/josanabr/ansible-k8s.

This is kubectl version:

Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

unable to add new book

I suppose that server doesn't run properly, which make it unable to add new book. Here is the error log for server image:
image

Here's my docker version:

Client: Docker Engine - Community
Cloud integration: v1.0.22
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:48 2021
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Desktop
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:56 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit:

de40ad0

and here's my docker-compose version:

docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019

the project runs, but somehow unable to add new book:
image
after I click "Submit", there is no book showing in the webpage, press F5, still nothing

Dependencies

After 2 hours of fixing different import errors, i have removed some specific versions from server requirements.
And my server container has run.

Follow lines has no versions:
Flask
Flask-Cors
flask-migrate
Flask-SQLAlchemy

This project is still relevant these days !!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.