Skip to content

Commit 9e401d7

Browse files
committed
Flask Xray integration with Kubernetes + POC
Signed-off-by: Anish Dhanka <anish@bjshomedelivery.com>
1 parent 86248a5 commit 9e401d7

File tree

13 files changed

+342
-2
lines changed

13 files changed

+342
-2
lines changed

sample-apps/flask/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./kubernetes

sample-apps/flask/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Docker build
2+
```
3+
$ docker build -t anishdhanka/flask-xray -f Dockerfile .
4+
5+
```
6+
7+
# Kubernetes Install
8+
```
9+
$ cd kubernetes && helm install flask-xray --namespace development .
10+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: flask-xray
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "flask-xray.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "flask-xray.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "flask-xray.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "flask-xray.labels" -}}
37+
helm.sh/chart: {{ include "flask-xray.chart" . }}
38+
{{ include "flask-xray.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "flask-xray.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "flask-xray.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
app: {{ include "flask-xray.name" . }}
52+
tier: backend
53+
{{- end }}
54+
55+
{{/*
56+
Create the name of the service account to use
57+
*/}}
58+
{{- define "flask-xray.serviceAccountName" -}}
59+
{{- if .Values.serviceAccount.create }}
60+
{{- default (include "flask-xray.fullname" .) .Values.serviceAccount.name }}
61+
{{- else }}
62+
{{- default "default" .Values.serviceAccount.name }}
63+
{{- end }}
64+
{{- end }}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "flask-xray.fullname" . }}
5+
labels:
6+
{{- include "flask-xray.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
revisionHistoryLimit: 5
12+
selector:
13+
matchLabels:
14+
{{- include "flask-xray.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
{{- with .Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "flask-xray.selectorLabels" . | nindent 8 }}
23+
spec:
24+
terminationGracePeriodSeconds: 120
25+
{{- with .Values.imagePullSecrets }}
26+
imagePullSecrets:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
29+
serviceAccountName: {{ include "flask-xray.serviceAccountName" . }}
30+
securityContext:
31+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
32+
containers:
33+
- name: {{ .Chart.Name }}
34+
securityContext:
35+
{{- toYaml .Values.securityContext | nindent 12 }}
36+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
37+
imagePullPolicy: {{ .Values.image.pullPolicy }}
38+
env:
39+
- name: LISTEN_ADDRESS
40+
value: '0.0.0.0:5000'
41+
- name: AWS_XRAY_DAEMON_ADDRESS
42+
value: {{ .Values.AWS_XRAY_DAEMON_ADDRESS }}
43+
ports:
44+
- name: http
45+
containerPort: 5000
46+
protocol: TCP
47+
resources:
48+
{{- toYaml .Values.resources | nindent 12 }}
49+
livenessProbe:
50+
httpGet:
51+
path: /
52+
port: http
53+
initialDelaySeconds: 30
54+
timeoutSeconds: 1
55+
periodSeconds: 10
56+
successThreshold: 1
57+
failureThreshold: 3
58+
readinessProbe:
59+
httpGet:
60+
path: /
61+
port: http
62+
initialDelaySeconds: 30
63+
timeoutSeconds: 1
64+
periodSeconds: 10
65+
successThreshold: 1
66+
failureThreshold: 3
67+
{{- with .Values.nodeSelector }}
68+
nodeSelector:
69+
{{- toYaml . | nindent 8 }}
70+
{{- end }}
71+
{{- with .Values.affinity }}
72+
affinity:
73+
{{- toYaml . | nindent 8 }}
74+
{{- end }}
75+
{{- with .Values.tolerations }}
76+
tolerations:
77+
{{- toYaml . | nindent 8 }}
78+
{{- end }}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2beta1
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "flask-xray.fullname" . }}
6+
labels:
7+
{{- include "flask-xray.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "flask-xray.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
21+
{{- end }}
22+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
23+
- type: Resource
24+
resource:
25+
name: memory
26+
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
27+
{{- end }}
28+
{{- end }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- if .Values.budget.minAvailable -}}
2+
apiVersion: policy/v1beta1
3+
kind: PodDisruptionBudget
4+
metadata:
5+
name: {{ include "flask-xray.fullname" . }}
6+
spec:
7+
selector:
8+
matchLabels:
9+
app.kubernetes.io/name: {{ include "flask-xray.name" . }}
10+
minAvailable: {{ .Values.budget.minAvailable }}
11+
{{- end -}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "flask-xray.fullname" . }}
5+
labels:
6+
{{- include "flask-xray.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "flask-xray.selectorLabels" . | nindent 4 }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "flask-xray.serviceAccountName" . }}
6+
labels:
7+
{{- include "flask-xray.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
{{- end }}

0 commit comments

Comments
 (0)