from flask import Flask, request, redirect, url_for, render_template_string import os import psycopg2 app = Flask(__name__) DB_HOST = os.getenv("DB_HOST") DB_NAME = os.getenv("DB_NAME") DB_USER = os.getenv("DB_USER") DB_PASSWORD = os.getenv("DB_PASSWORD") def get_db(): conn = psycopg2.connect( host=DB_HOST, database=DB_NAME, user=DB_USER, password=DB_PASSWORD ) return conn def init_db(): conn = get_db() cur = conn.cursor() cur.execute(""" CREATE TABLE IF NOT EXISTS items ( id SERIAL PRIMARY KEY, text TEXT NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) """) conn.commit() cur.close() conn.close() init_db() TEMPLATE = """ Cloud Notes Platform

Cloud Notes Platform

A modern cloud-native Flask application deployed with Kubernetes, Docker containers, persistent storage, and automated deployment workflows. This platform demonstrates scalable cloud infrastructure concepts and production-ready deployment architecture.

Running Mode: {{ mode }}

Create New Note

Total Notes

{{ items|length }}

Infrastructure

K8s

Stored Notes

{% for item in items %}
Note #{{ item.id }} {{ item.created }}
{{ item.text }}
{% else %}
No notes stored yet.
{% endfor %}
""" @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": text = request.form.get("text", "").strip() if text: conn = get_db() cur = conn.cursor() cur.execute( "INSERT INTO items (text) VALUES (%s)", (text,) ) conn.commit() cur.close() conn.close() return redirect(url_for("index")) conn = get_db() cur = conn.cursor() cur.execute( "SELECT id, text, created FROM items ORDER BY id DESC" ) rows = cur.fetchall() items = [] for row in rows: items.append({ "id": row[0], "text": row[1], "created": row[2] }) cur.close() conn.close() mode = "Docker Compose + PostgreSQL" return render_template_string( TEMPLATE, items=items, mode=mode ) if __name__ == "__main__": app.run(host="0.0.0.0", port=5000)