GithubHelp home page GithubHelp logo

sachsenhofer / microservice_python Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 46 KB

This is a template for a Python microservice on Kubernetes

Home Page: https://sachsenhofer.io

Python 100.00%
microservice python flask kubernetes gcloud google-cloud

microservice_python's Introduction

microservice_python

This is a template for a Python microservice on Kubernetes.


Checkout repository:

git clone https://github.com/sachsenhofer/microservice_python.git

App

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return '<html><head></head><body>Hello World!</body></html>'

@app.route('/health')
def health():
    return '0'

if __name__ == '__main__':
    app.run(debug=False, host='0.0.0.0', port=8080)

Dockerfile

FROM ubuntu:latest
MAINTAINER Dominik Sachsenhofer "[email protected]"

RUN apt-get update
RUN apt-get install -y python-pip python-dev build-essential wget curl
COPY . /app
WORKDIR /app

RUN pip install -r requirements.txt

EXPOSE 8080

ENTRYPOINT ["python"]

CMD ["app.py"]

Usage

Build

Builds the Docker image.

Execute in terminal:

sudo docker build -t microservice-python:latest .

Push

Pushes an image or a repository to the Google Container Registry.

A Google Cloud account is needed. Replace 'public-207110' with your own Project-ID.

Execute in terminal:

sudo docker tag microservice-python:latest eu.gcr.io/public-207110/microservice-python:latest
sudo docker push eu.gcr.io/public-207110/microservice-python:latest

Pull

Pulls the image from the Google Container Registry.

Execute in terminal:

sudo docker pull eu.gcr.io/public-207110/microservice-python:latest

Run

Runs the image on your local machine.

Execute in terminal:

sudo docker run -p 8080:8080 eu.gcr.io/public-207110/microservice-python:latest

Deploy

Deploys the application to the Kubernetes cluster.

Execute in terminal:

kubectl create -f deploy/kubernetes

Check all ressources that have been created:

kubectl get deployments,pods,services -n microservice
NAME                             DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/microservice-python-dep   2         2         2            2           2m

NAME                                          READY     STATUS    RESTARTS   AGE
po/microservice-python-dep-6b6dbdfb44-krtl7   1/1       Running   0          2m
po/microservice-python-dep-6b6dbdfb44-rpp7x   1/1       Running   0          2m

NAME                          TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
svc/microservice-python-svc   LoadBalancer   10.63.251.103   104.155.76.135   8080:30667/TCP   2m

Delete

To delete all resources, execute the following command.

Execute in terminal:

kubectl delete -f deploy/kubernetes

microservice_python's People

Contributors

sachsenhofer avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.