Skip to content

Instantly share code, notes, and snippets.

@danquack
Created June 17, 2020 02:32
Show Gist options
  • Save danquack/b7781b1d27948eedef24758a352e594a to your computer and use it in GitHub Desktop.
Save danquack/b7781b1d27948eedef24758a352e594a to your computer and use it in GitHub Desktop.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app
labels:
app: flask
spec:
selector:
matchLabels:
app: flask
template:
metadata:
labels:
app: flask
spec:
automountServiceAccountToken: true
serviceAccountName: <SERVICE_ACCOUNT_NAME>
containers:
- name: flask
env:
- name: AWS_DEFAULT_REGION
value: us-east-1
- name: S3_BUCKET
value: <NAME_OF_S3_BUCKET>
image: <IMAGE_REPOSITORY>
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /
port: 5000
scheme: HTTP
ports:
- containerPort: 5000
protocol: TCP
readinessProbe:
httpGet:
path: /test
port: 5000
scheme: HTTP
resources:
requests:
cpu: 250m
memory: 50Mi
from os import environ
from flask import Flask
from boto3 import client, resource
app = Flask(__name__)
@app.route('/')
def init():
try:
return "app is up"
except:
return "environ S3_BUCKET variable not set", 500
@app.route('/test')
def homepage():
try:
s3 = resource('s3')
obj = s3.Object(environ['S3_BUCKET'], 'test')
return obj.get()['Body'].read().decode('utf-8')
except:
return "Error getting param", 403
if __name__ == "__main__":
app.run(host='0.0.0.0')
---
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
eks.amazonaws.com/role-arn: <ARN_OF_ROLE_FOR_TESTING>
name: s3-reader
---
apiVersion: v1
kind: Service
metadata:
labels:
app: flask
name: flask-app
spec:
ports:
- port: 80
protocol: TCP
targetPort: 5000
selector:
app: flask
sessionAffinity: None
type: ClusterIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment