From 3b91f7ee2619947dcd0000342812c74f6db9a1a4 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 29 Sep 2020 22:08:20 +0000 Subject: [PATCH] init --- .gitignore | 2 ++ certificate.yaml | 12 ++++++++++++ deployment.yaml | 46 ++++++++++++++++++++++++++++++++++++++++++++ ingress.yaml | 20 +++++++++++++++++++ service.yaml | 25 ++++++++++++++++++++++++ src/Dockerfile | 12 ++++++++++++ src/app.py | 20 +++++++++++++++++++ src/requirements.txt | 8 ++++++++ voyager-ingress.yaml | 16 +++++++++++++++ 9 files changed, 161 insertions(+) create mode 100644 .gitignore create mode 100644 certificate.yaml create mode 100644 deployment.yaml create mode 100644 ingress.yaml create mode 100644 service.yaml create mode 100644 src/Dockerfile create mode 100644 src/app.py create mode 100644 src/requirements.txt create mode 100644 voyager-ingress.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82adb58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +venv diff --git a/certificate.yaml b/certificate.yaml new file mode 100644 index 0000000..206228d --- /dev/null +++ b/certificate.yaml @@ -0,0 +1,12 @@ +apiVersion: cert-manager.io/v1alpha3 +kind: Certificate +metadata: + name: test-redis +spec: + dnsNames: + - test-redis.endofeternity.ca + issuerRef: + group: cert-manager.io + kind: ClusterIssuer + name: letsencrypt-prod + secretName: test-redis-tls-certificate diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 0000000..8514f4d --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-redis + labels: + app: test-redis +spec: + replicas: 1 + selector: + matchLabels: + app: test-redis + template: + metadata: + labels: + app: test-redis + spec: + containers: + - name: test-redis + image: aarch64/redis + ports: + - containerPort: 6379 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-redis-http + labels: + app: test-redis-http +spec: + replicas: 2 + selector: + matchLabels: + app: test-redis-http + template: + metadata: + labels: + app: test-redis-http + spec: + containers: + - name: test-redis-http + image: docker.endofeternity.ca/test-redis-http:v2 + ports: + - containerPort: 80 + name: test-redis-http + protocol: TCP + diff --git a/ingress.yaml b/ingress.yaml new file mode 100644 index 0000000..b3a4ee2 --- /dev/null +++ b/ingress.yaml @@ -0,0 +1,20 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: test-redis + annotations: + kubernetes.io/ingress.class: nginx + certmanager.io/cluster-issuer: letsencrypt-prod +spec: + tls: + - hosts: + - test-redis.endofeternity.ca + secretName: test-redis-tls-certificate + rules: + - host: test-redis.endofeternity.ca + http: + paths: + - backend: + serviceName: test-redis-http + servicePort: 80 + path: / diff --git a/service.yaml b/service.yaml new file mode 100644 index 0000000..e02738a --- /dev/null +++ b/service.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: Service +metadata: + name: test-redis +spec: + type: ClusterIP + ports: + - name: redis + port: 6379 + targetPort: 6379 + selector: + app: test-redis +--- +apiVersion: v1 +kind: Service +metadata: + name: test-redis-http +spec: + type: ClusterIP + ports: + - name: http + port: 80 + targetPort: 8000 + selector: + app: test-redis-http diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..fe66e3f --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.7-alpine + +COPY requirements.txt / + +RUN pip install -r /requirements.txt + +COPY app.py app/app.py +WORKDIR /app + +EXPOSE 8000 + +ENTRYPOINT ["gunicorn", "-b 0.0.0.0:8000", "-w 4", "app:app"] diff --git a/src/app.py b/src/app.py new file mode 100644 index 0000000..ce26ccc --- /dev/null +++ b/src/app.py @@ -0,0 +1,20 @@ +from flask import Flask +import os +import redis +app = Flask(__name__) +redis_host = 'test-redis' +print("Redis host %s", redis_host) +r = redis.Redis(host=redis_host, port=6379, db=0) + +@app.route('/') +def hello(): + return "Hello There, World!" + +@app.route('/') +def hello_stranger(name=None): + times = r.incr(name) + return "Hello, %s! You have visited %s times.\n\n%s" % (name, times, os.environ['HOSTNAME']) + + +if __name__ == '__main__': + app.run() diff --git a/src/requirements.txt b/src/requirements.txt new file mode 100644 index 0000000..cb3e86a --- /dev/null +++ b/src/requirements.txt @@ -0,0 +1,8 @@ +click==7.1.2 +Flask==1.1.2 +gunicorn==20.0.4 +itsdangerous==1.1.0 +Jinja2==2.11.2 +MarkupSafe==1.1.1 +redis==3.5.3 +Werkzeug==1.0.1 diff --git a/voyager-ingress.yaml b/voyager-ingress.yaml new file mode 100644 index 0000000..5e620b9 --- /dev/null +++ b/voyager-ingress.yaml @@ -0,0 +1,16 @@ +apiVersion: voyager.appscode.com/v1beta1 +kind: Ingress +metadata: + name: test-ingress + namespace: default + annotations: + ingress.appscode.com/type: LoadBalancer +spec: + rules: + - host: test-redis.endofeternity.ca + http: + paths: + - path: '/' + backend: + serviceName: test-redis-http + servicePort: '80'