GithubHelp home page GithubHelp logo

jake-shobin / helm-sample-flask-project Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shawnsnyk/helm-sample-flask-project

0.0 0.0 0.0 161 KB

Sample projects using helm for deployment

Python 6.41% Makefile 42.21% Smarty 45.86% Dockerfile 5.52%

helm-sample-flask-project's Introduction

Sample Flask project deploying on Kubernetes

This repository is a sample python Flask app, that can be deployed on Kubernetes using CircleCI. You can use this project as a template to deploy your app on Teko Kubernetes cluster, CI/CD pipeline with CircleCI.

  • Flask application
  • CI/CD using CircleCI
  • Celery
  • Redis pubsub

Integration Guide

In order to deploy your app on Kubernetes, some basic knowledge about Kubernetes and Docker is required. The template uses helm to simplify the deployment.

Prerequisites

  • Installing kubectl
    • To access Kubernetes cluster, ask SA team to obtain your config file, then place it at $HOME/.kube
  • Installing helm
    • Initialize helm using command: helm init --client-only
  • An account to access Docker registry and helm chart repository which is Harbor
    • Ask SA team to create your project and account.

Edit your values.yaml

A helm chart is created to simplify deployment: https://github.com/teko-vn/helm-charts/tree/master/flaskapp. Just copy values.yaml then edit its values to your own values.

NOTE: In this repo, values-tpl.yaml is used with a placeholder {{ branch }}. This placeholder will be replaced to deploy your app in different environments. The file is placed at <project_root>/deployments/k8s/ directory to work with Makefile in CI configuration

  1. nameOverride, fullnameOverride: Your app name in short and long description. You need to provide both.

  2. replicaCount: The number of instances your app will launch.

  3. image: Docker Image config

    • registry: Docker image registry. Ex: gcr.io (Google Cloud Container Registry), docker.io (Docker Hub), hub.k8s.teko.vn (Teko Harbor). If you leave this empty, Docker Hub will be used.
    • repository: The path your Docker image. Ex: hello-flask/hell-flask
    • tag: The image tag. Ex: 1.0.0, 1.2.0...
    • port: The container's port.
    • pullPolicy: Image pull policy. Ex: Always, IfNotPresent
    • dockerConfig: docker config json file. The file can be found at $HOME/.docker/config.json after you login to the registry by calling docker login <registry>
  4. healthcheck: Health-check

    • enabled: true to enable heath-check.
    • liveness: HTTP URL to check your app's liveness.
    • readiness: HTTP URL to check your app's readiness.
    • host: HTTP host header when calling HTTP GET request to health-check URLs.
  5. hosts: An array of your app's hosts.

    • host: your app's host. Ex: myapp.k8s.teko.vn
    • paths: an array of URI paths. Leave it "", so all requests to host will be routed to your service.
    • Example
       - host: myapp.k8s.teko.vn
         paths:
           - "/api"
       - "/api/v1"
      
      so all requests to myapp.k8s.teko.vn/api and myapp.k8s.teko.vn/api/v1 will be routed to your service.
  6. secrets: your app's secrets

    It is an array of key-value pair. Example:

    secrets:
      - db-url: "mysql://user:passw@host:3306/mydb"
      - amqp-url: "amqp://user:[email protected]/teko-prod"
    
  7. environmentVariables: your app's environment variables.

    It can be a string or a value from your apps' secrets. Example:

    environmentVariables:
    - name: FLASK_CONFIG
      value: production
    - name: DATABASE_URL
      valueFromSecret: db-url
    

Configure CI

Sample CircleCI configuration file at config.yml. A Makefile is created for some commands. You can edit these files to suit your needs.

NOTE: The values file (values-tpl.yaml) edited in previous step should be placed at <project_root>/deployments/k8s/ directory to work with Makefile.

  1. Makefile

    You need to provide your project' values, which are at top of the Makefile:

    PROJECT_NAME := hello-flask
    IMAGE_REPO := hub.k8s.teko.vn/hello-flask/hello-flask
    HARBOR_SERVER := https://hub.k8s.teko.vn
    
  2. .circleci/config.yml

    There are two workflows configured:

    • feature-development

      When a feature is developed at feature/* branch, it can be deployed at <your-app>-<short-branch-name>.k8s.teko.vn.

      When feature is merged to master branch, it can be deployed to staging for UAT testing.

    • deploy-production

      When a git tag is created, following semver convention (Ex: v0.1.1, v1.2.0...), your app is ready to deploy on production environment.

  3. Configure CirleCI environments

    Some environment variables is required to configure at your project CircleCI settings.

    • DEV_KUBE_CONFIG: kubectl config file for k8s development cluster. This value must be base64 encoded.
    • PROD_KUBE_CONFIG: kubectl config file for k8s production cluster. This value must be base64 encoded.
    • HARBOR_USERNAME: Harbor username, which is needed to use Teko Harbor for image registry and flaskapp helm chart.
    • HARBOR_PASSWORD: Harbor password, which is needed to use Teko Harbor for image registry and flaskapp helm chart.

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.