From 19d81fbc3f873a38124ad91256ed87d68da05c67 Mon Sep 17 00:00:00 2001 From: welld1 Date: Tue, 2 Jun 2020 21:17:11 -0400 Subject: [PATCH] add example --- example/docker-compose.yml | 57 ++++++++++++++++++++++++++++++++ example/templates/configmap.yaml | 9 +++++ example/templates/deploy.yaml | 33 ++++++++++++++++++ example/templates/hpa.yaml | 18 ++++++++++ example/templates/ingress.yaml | 17 ++++++++++ example/templates/secret.yaml | 11 ++++++ example/templates/service.yaml | 19 +++++++++++ example/test.py | 16 +++++++++ 8 files changed, 180 insertions(+) create mode 100755 example/docker-compose.yml create mode 100644 example/templates/configmap.yaml create mode 100644 example/templates/deploy.yaml create mode 100644 example/templates/hpa.yaml create mode 100755 example/templates/ingress.yaml create mode 100644 example/templates/secret.yaml create mode 100644 example/templates/service.yaml create mode 100644 example/test.py diff --git a/example/docker-compose.yml b/example/docker-compose.yml new file mode 100755 index 0000000..7800c74 --- /dev/null +++ b/example/docker-compose.yml @@ -0,0 +1,57 @@ +version: '3.5' + +services: + ldapi: + build: . + image: dtr.aws.e1.nwie.net/reese/ldapi:1.0.5 + labels: + - "traefik.http.routers.ldapi.rule=Host(`ldapi.localhost`)" + - "traefik.http.services.ldapi-service.loadbalancer.server.port=8080" + volumes: + - ./manage.py:/app/manage.py + - ./config:/app/config + - ./ldapi:/app/ldapi + environment: + - DEBUG=True + - SECRET_KEY=secret + - FERNET_KEY=egj316Q7UsjVuBjnXxvcNFBIU8FNTdgk-bVnBJ-uz68= + - HOSTS=ldapi.localhost + - DJANGO_SUPERUSER_PASSWORD=django + depends_on: + - traefik + + postgres: + image: postgres:12 + volumes: + - data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + + pgadmin: + image: dpage/pgadmin4:4 + labels: + - "traefik.http.routers.pgadmin.rule=Host(`pgadmin.localhost`)" + - "traefik.http.services.pgadmin-service.loadbalancer.server.port=80" + volumes: + - pgadmin:/var/lib/pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: postgres + PGADMIN_DEFAULT_PASSWORD: postgres + depends_on: + - traefik + + traefik: + image: traefik:v2.2 + labels: + - "traefik.http.routers.traefik.rule=Host(`traefik.localhost`)" + - "traefik.http.services.traefik-service.loadbalancer.server.port=8080" + command: --api.insecure=true --providers.docker --log.level=ERROR --accesslog=true + ports: + - "80:80" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + +volumes: + data: + pgadmin: \ No newline at end of file diff --git a/example/templates/configmap.yaml b/example/templates/configmap.yaml new file mode 100644 index 0000000..17ce7a1 --- /dev/null +++ b/example/templates/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }} + labels: + app: {{ .Release.Name }} +data: + HOSTS: {{ .Values.host }} + DEBUG: "False" \ No newline at end of file diff --git a/example/templates/deploy.yaml b/example/templates/deploy.yaml new file mode 100644 index 0000000..d55df5e --- /dev/null +++ b/example/templates/deploy.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ .Release.Name }} + spec: + containers: + - image: {{ required "A valid .Values.image entry required!" .Values.image }}:{{ required "A valid .Values.tag entry required!" .Values.tag }} + name: {{ .Release.Name }}-web + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: {{ .Release.Name }} + - secretRef: + name: {{ .Release.Name }} + - secretRef: + name: postgres + resources: + limits: + memory: "500Mi" + cpu: "250m" + requests: + memory: "1Mi" + cpu: "100m" \ No newline at end of file diff --git a/example/templates/hpa.yaml b/example/templates/hpa.yaml new file mode 100644 index 0000000..ae6c254 --- /dev/null +++ b/example/templates/hpa.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2beta2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ .Release.Name }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ .Release.Name }} + minReplicas: 1 + maxReplicas: 12 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 \ No newline at end of file diff --git a/example/templates/ingress.yaml b/example/templates/ingress.yaml new file mode 100755 index 0000000..45e6a2a --- /dev/null +++ b/example/templates/ingress.yaml @@ -0,0 +1,17 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ .Release.Name }} + annotations: + kubernetes.io/ingress.class: default +spec: + tls: + - hosts: + - {{ required "A valid .Values.host entry required!" .Values.host }} + rules: + - host: {{ required "A valid .Values.host entry required!" .Values.host }} + http: + paths: + - backend: + serviceName: {{ .Release.Name }} + servicePort: 8080 \ No newline at end of file diff --git a/example/templates/secret.yaml b/example/templates/secret.yaml new file mode 100644 index 0000000..cef026e --- /dev/null +++ b/example/templates/secret.yaml @@ -0,0 +1,11 @@ +{{ if .Values.secrets }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }} +type: generic +data: + SECRET_KEY: {{ randAlphaNum 64 | b64enc | quote }} + DJANGO_SUPERUSER_PASSWORD: {{ randAlphaNum 64 | b64enc | quote }} + FERNET_KEY: {{ randAlphaNum 32 | b64enc | b64enc | quote }} +{{ end }} \ No newline at end of file diff --git a/example/templates/service.yaml b/example/templates/service.yaml new file mode 100644 index 0000000..ee80878 --- /dev/null +++ b/example/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: {{ .Release.Name }} + name: {{ .Release.Name }} +spec: + ports: + - port: 8080 + protocol: TCP + name: {{ .Release.Name }}-web + targetPort: 8080 + - port: 5432 + protocol: TCP + name: {{ .Release.Name }}-pg + targetPort: 5432 + selector: + app: {{ .Release.Name }} # This selects the pod(s) that match the selector + type: ClusterIP \ No newline at end of file diff --git a/example/test.py b/example/test.py new file mode 100644 index 0000000..07c4516 --- /dev/null +++ b/example/test.py @@ -0,0 +1,16 @@ +import getpass +import threading +import requests +import time +from requests.auth import HTTPBasicAuth + +def timer(func, *args, **kwargs): + then = time.time() + func(*args, **kwargs) + print(time.time() - then) + +user = getpass.getuser() +password = getpass.getpass() +me = lambda num: print(num) or print(requests.get('https://ldapi.apps-test.aws.e1.nwie.net/me/', verify="/etc/ssl/ca-bundle.pem", auth=HTTPBasicAuth(user, password))) +threadme = lambda num: threading.Thread(target=timer, args=(me, num)).start() +[threadme(y) for y in range(0,1000)] \ No newline at end of file