Skip to content

Commit

Permalink
predict api helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
123MwanjeMike committed Nov 15, 2022
1 parent e768505 commit 8dbc907
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
k8s/nginx/*/global-config.yaml
k8s/*/templates/
k8s/**/templates/
File renamed without changes.
6 changes: 3 additions & 3 deletions k8s/predict/Chart.yaml → k8s/predict/api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
appVersion: "1.0"
apiVersion: v2
appVersion: "1.16.0"
description: AirQo Prediction Helm Chart
name: airqo-prediction-api
home: https://airqo.net
version: 0.1.0
maintainers:
maintainers:
- name: AirQo
email: [email protected]
url: https://airqo.net
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "airqo-device-registry-api.fullname" . }})
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "airqo-prediction-api.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "airqo-device-registry-api.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "airqo-device-registry-api.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "airqo-prediction-api.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "airqo-prediction-api.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "airqo-device-registry-api.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "airqo-prediction-api.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
51 changes: 51 additions & 0 deletions k8s/predict/api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "airqo-prediction-api.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "airqo-prediction-api.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "airqo-prediction-api.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "airqo-prediction-api.labels" -}}
helm.sh/chart: {{ include "airqo-prediction-api.chart" . }}
{{ include "airqo-prediction-api.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "airqo-prediction-api.selectorLabels" -}}
app.kubernetes.io/name: {{ include "airqo-prediction-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
82 changes: 82 additions & 0 deletions k8s/predict/api/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.app.name }}
namespace: {{ .Values.app.namespace }}
labels:
{{- include "airqo-prediction-api.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
app: {{ .Values.app.label }}
replicas: {{ .Values.replicaCount }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
{{- with .Values.strategy }}
strategy:
{{- toYaml . | nindent 8 }}
{{- end }}
minReadySeconds: {{ .Values.minReadySeconds }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
app: {{ .Values.app.label }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Values.app.label }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.targetPort }}
name: {{ .Values.app.label }}
# livenessProbe:
# httpGet:
# path: /health
# port: 5000
# readinessProbe:
# httpGet:
# path: /health
# port: 5000
# initialDelaySecond: 5
# periodSeconds: 3
# successThreshold: 1
envFrom:
- configMapRef:
name: {{ .Values.app.configmap }}
{{- with .Values.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
31 changes: 31 additions & 0 deletions k8s/predict/api/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: '{{ .Values.app.name }}-hpa'
namespace: {{ .Values.app.namespace }}
labels:
{{- include "airqo-prediction-api.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.app.name }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
15 changes: 15 additions & 0 deletions k8s/predict/api/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: "{{ .Values.app.name }}-svc"
labels: { { - include "airqo-prediction-api.labels" . | nindent 4 } }
namespace: { { .Values.app.namespace } }
spec:
type: { { .Values.service.type } }
ports:
- port: { { .Values.service.port } }
targetPort: { { .Values.service.targetPort } }
protocol: { { .Values.service.protocol } }
nodePort: { { .Values.service.nodePort } }
selector:
app: { { .Values.app.label } }
15 changes: 15 additions & 0 deletions k8s/predict/api/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "airqo-prediction-api.fullname" . }}-test-connection"
labels:
{{ include "airqo-prediction-api.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "airqo-prediction-api.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
90 changes: 90 additions & 0 deletions k8s/predict/api/values-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
app:
name: airqo-prediction-api
label: prediction-api
namespace: production
configmap: env-predict-production

replicaCount: 3

revisionHistoryLimit: 2

strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1

minReadySeconds: 5

affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
preference:
matchExpressions:
- key: node-type
operator: In
values:
- general-purpose

image:
repository: gcr.io/airqo-250220/airqo-prediction-api
pullPolicy: Always
tag: latest

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}

podSecurityContext:
{}
# fsGroup: 2000

securityContext:
{}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

resources:
limits:
cpu: 50m
memory: 200Mi
requests:
# Average usage was 0.0007 vCPU and 120Mi over the last 30 days
cpu: 5m
memory: 120Mi

volumeMounts:
- name: config-volume
mountPath: /etc/config

volumes:
- name: config-volume
configMap:
name: env-predict-production-files

nodeSelector: {}

tolerations: []

ingress:
enabled: false

service:
type: NodePort
port: 5000
protocol: TCP
targetPort: 5000
nodePort: 30009

autoscaling:
minReplicas: 1
maxReplicas: 3
# targetCPUUtilizationPercentage: 70
targetMemoryUtilizationPercentage: 70
Loading

0 comments on commit 8dbc907

Please sign in to comment.