From 29ab885606b05cea7dd8db9a13e8a6fcb9838131 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sat, 9 Oct 2021 21:11:24 -0400 Subject: [PATCH] working helm chart --- .gitignore | 1 + Makefile | 12 +++++++++ README.md | 15 ++++++++++- app/Dockerfile | 27 +++++++++++++++++++ app/app.py | 18 +++++++++++++ app/requirements.txt | 2 ++ charts/demo-helm/Chart.yaml | 7 +++++ .../demo-helm/templates/backend-service.yaml | 13 +++++++++ charts/demo-helm/templates/backend.yaml | 23 ++++++++++++++++ charts/demo-helm/templates/ingress.yaml | 14 ++++++++++ 10 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 app/Dockerfile create mode 100644 app/app.py create mode 100644 app/requirements.txt create mode 100644 charts/demo-helm/Chart.yaml create mode 100644 charts/demo-helm/templates/backend-service.yaml create mode 100644 charts/demo-helm/templates/backend.yaml create mode 100644 charts/demo-helm/templates/ingress.yaml diff --git a/.gitignore b/.gitignore index f8b73e7..37a1417 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,4 @@ dmypy.json # Cython debug symbols cython_debug/ +.idea/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6c0d923 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ + +IMAGE_NAME=registry.runcible.io/demo-helm +IMAGE_VERSION=1.0.1 + +push-app-image: build-app-image + docker push $(IMAGE_NAME):$(IMAGE_VERSION) + +build-app-image: + docker build -t $(IMAGE_NAME):$(IMAGE_VERSION) ./app + +check: + echo $(IMAGE_NAME):$(IMAGE_VERSION) \ No newline at end of file diff --git a/README.md b/README.md index af2e110..cf56fee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,16 @@ # demo-helm -A demo helm chart to deploy a simple web app written in Python \ No newline at end of file +A demo helm chart to deploy a simple web app written in Python + + +## Setting registry pull secrets + +From: [The k8s docs](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line) + +``` +kubectl create secret docker-registry regcred \ + --docker-server= \ + --docker-username= \ + --docker-password= \ + --docker-email= +``` \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..ffac877 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,27 @@ +# Base Image +FROM python:3.7.3-stretch + +ENV APP_HOME=/opt/app + +# Create directory for the app +RUN mkdir $APP_HOME +WORKDIR $APP_HOME + +# Create the app user +RUN groupadd app && useradd -g app app + +# Install Requirements +COPY requirements.txt . + +RUN pip install --no-cache -r requirements.txt + +# Install app +COPY app.py . + +# Chown all the files to the app user +RUN chown -R app:app $APP_HOME + +# Change to the app user +USER app + +CMD gunicorn --log-level=debug -b 0.0.0.0:5000 app:app diff --git a/app/app.py b/app/app.py new file mode 100644 index 0000000..c7bfc55 --- /dev/null +++ b/app/app.py @@ -0,0 +1,18 @@ +import os +from flask import Flask + +app = Flask(__name__) + +__version__ = "1.0.0" + +@app.route("/ping") +@app.route("/") +def pong(): + """A simple ping route.""" + return {"message": "pong"} + + +@app.route("/env") +def env(): + """Exposes the environment variables.""" + return dict(os.environ) diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..101b36f --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1,2 @@ +flask==2.0.2 +gunicorn==20.1.0 \ No newline at end of file diff --git a/charts/demo-helm/Chart.yaml b/charts/demo-helm/Chart.yaml new file mode 100644 index 0000000..a17bb6b --- /dev/null +++ b/charts/demo-helm/Chart.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v2 +name: demo-helm +appVersion: 1.0.1 +description: A Helm chart to practice helm +version: 0.1.1 +type: application diff --git a/charts/demo-helm/templates/backend-service.yaml b/charts/demo-helm/templates/backend-service.yaml new file mode 100644 index 0000000..e91ce27 --- /dev/null +++ b/charts/demo-helm/templates/backend-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: backend + name: backend +spec: + ports: + - protocol: 'TCP' + port: 80 + targetPort: 5000 + selector: + app: backend diff --git a/charts/demo-helm/templates/backend.yaml b/charts/demo-helm/templates/backend.yaml new file mode 100644 index 0000000..b775e34 --- /dev/null +++ b/charts/demo-helm/templates/backend.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - image: registry.runcible.io/demo-helm:1.0.1 + imagePullPolicy: Always + name: backend + ports: + - name: backend + containerPort: 5000 + imagePullSecrets: + - name: regcred \ No newline at end of file diff --git a/charts/demo-helm/templates/ingress.yaml b/charts/demo-helm/templates/ingress.yaml new file mode 100644 index 0000000..22fa287 --- /dev/null +++ b/charts/demo-helm/templates/ingress.yaml @@ -0,0 +1,14 @@ +apiVersion: extensions/v1beta1 +# apiVersion: networking.k8s.io/v1 # Supposed to be the new API but of course the spec structure has changed. +kind: Ingress +metadata: + name: demo-helm-ingress +spec: + rules: + - host: backend.runcible.io + http: + paths: + - path: / + backend: + serviceName: backend + servicePort: 80