Can you please help me on below assignment … I would be thankful to you…
Assignment
Your task is to accomplish the following:
- Deploy the sample python applications to a cluster of nodes using a container orchestration framework
- Application A should be publicly accessible over HTTPS
- Application B should not be accessible via the public internet
- Please show how you would auto-scale the number of nodes and containers as the number of requests increases.
- Bonus work : Use Nginx to host it with HTTP and then :
-
Enable HTTPS and redirect HTTP to HTTPS
-
Create a self-signed certificate or use LetsEncrypt, also document the commands you are using to create the certificate
For delivery of this assignment, we’d like to see:
- A Dockerfile for each application
- Framework for deploying containers to a group of nodes
- Document how you will use continuous delivery to ship to a production environment
- Scripts and/or docs involved with automatically scaling the application and nodes horizontally based on requests
- Nginx configuration file (optional, bonus task)
Getting Started in Local Development
Please create and source your virtualenv before beginning.
Running the apps locally:
pip install -r requirements.txt
sqlite3 database.db < schema.sql
python app_a.py
python app_b.py
Making a request
curl -X POST -H 'Authorization: mytoken' http://127.0.0.1:5000/jobs
Simulating a lot of requests
ab -m POST -H "Authorization: mytoken" -n 500 -c 4 http://127.0.0.1:5000/jobs
----------------------------------------------------------------------------------------------------------------------------
- =============================================
- cat requirements.txt
- flask>=0.12.3
- requests>=2.20.0
- ============================================
- cat database.db
- P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)▒▒ableusersusersCREATE TABLE users (
- id integer primary key autoincrement,
- username text not null,
- password text not null,
- ====================================================================
- cat schema.sql
- CREATE TABLE users (
- id integer primary key autoincrement,
- username text not null,
- password text not null,
- token text not null);
- INSERT INTO users (username, password, token) VALUES (‘density’, ‘password123’, ‘mytoken’);
- ===================================================================
- cat app_a.py
- from flask import Flask, request
- import requests
- application = Flask(name)
- @application.route(‘/hello’)
- def hello():
- return ‘Hello there’
- @application.route(‘/jobs’, methods=[‘POST’])
- def jobs():
- token = request.headers[‘Authorization’]
- data = {“token”: token}
- result = requests.post(‘http://0.0.0.0:5001/auth’, data=data).content
- if result == “density”:
- return ‘Jobs:\nTitle: Devops\nDescription: Awesome\n’
- else:
- return ‘fail’
- if name == “main”:
- application.run(host=‘0.0.0.0’, port=5000)
- ======================================================================
- cat app_b.py
- from flask import Flask, request
- import sqlite3 as sql
- application = Flask(name)
- @application.route(‘/auth’, methods=[‘POST’])
- def auth():
- try:
- token = request.form[‘token’]
- con = sql.connect(“database.db”)
- cur = con.cursor()
- cur.execute(
- “SELECT username from users where token = (?) LIMIT 1”,
- (token, ))
- username = cur.fetchone()[0]
- con.close()
- return username
- except:
- return ‘fail’
- if name == “main”:
- application.run(host=‘0.0.0.0’, port=5001)
- ===========================================================================