Taxonomy Icon

API Management

Deploy a Python Flask application in Kubernetes

Get the code

Summary

This code pattern creates a Python Flask application that incorporates MongoDB as a microservice in Docker containers. These containers are deployed in Kubernetes.

Description

In this code pattern, create a Work Log web application using Flask, MongoDB, and Kubernetes. The Work Log application is used to keep track of different types of days that are associated with work. The different types of days include:

  • Working in the office
  • Working remotely
  • Vacation days
  • Holidays
  • Sick days

After completing this pattern, you will understand how to:

  • Create a Python Flask application
  • Incorporate MongoDB into a Python application
  • Deploy and run microservices on Kubernetes

Flow

flow

  1. A user interacts with the App UI to initially create an account, log in to the account, or reset a password for their account. Once a user is logged in, they can view, add, and edit their work log data.
  2. The functionality of the App UI that the user interacts with is handled by React. React is where the API calls are initialized.
  3. The API calls are processed in the Flask API microservice on Kubernetes and are handled accordingly.
  4. The data is stored, gathered, and/or modified in MongoDB depending on the API calls.
  5. The response from the API calls are handled accordingly by the App UI.

Included components

  • IBM Cloud Container Service: IBM Bluemix Container Service manages highly available apps inside Docker containers and Kubernetes clusters on the IBM Cloud.
  • Swagger: A framework of API developer tools for the OpenAPI Specification that enables development across the entire API lifecycle.
  • Container Orchestration: Automating the deployment, scaling and management of containerized applications.
  • Microservices: Collection of fine-grained, loosely coupled services using a lightweight protocol to provide building blocks in modern application composition in the cloud.
  • Python: Python is a programming language that lets you work more quickly and integrate your systems more effectively.
  • Flask: A microframework for Python for building APIs.
  • React: JavaScript library for building User Interfaces.
  • MongoDB: A document NoSQL database.

Blog

Read the blog post that details how I created this web application.