From d6a92363d3d181fa5de11a52bac8fd504f0dd3b7 Mon Sep 17 00:00:00 2001 From: Antun Franjin Date: Tue, 16 Nov 2021 13:16:39 +0100 Subject: [PATCH 1/4] Add efc production deployments --- 02_hetzner/01_prod/efc-shop/deployment.yaml | 154 ++++++++++++ 02_hetzner/01_prod/efc/deployment.yaml | 251 ++++++++++++++++++++ 2 files changed, 405 insertions(+) create mode 100644 02_hetzner/01_prod/efc-shop/deployment.yaml create mode 100644 02_hetzner/01_prod/efc/deployment.yaml diff --git a/02_hetzner/01_prod/efc-shop/deployment.yaml b/02_hetzner/01_prod/efc-shop/deployment.yaml new file mode 100644 index 0000000..de772f0 --- /dev/null +++ b/02_hetzner/01_prod/efc-shop/deployment.yaml @@ -0,0 +1,154 @@ +# Deployment description +apiVersion: apps/v1 +kind: Deployment +metadata: + name: efc-shop-deployment + namespace: prod-environment + labels: + app: efc-shop +spec: + strategy: + type: Recreate + replicas: 1 + selector: + matchLabels: + app: efc-shop + template: + metadata: + labels: + app: efc-shop + spec: + containers: + - name: efc-shop-frontend + image: packages.semapp.lan:5000/efc-shop_frontend:prod + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "4" + ports: + - containerPort: 8501 + name: efc-shop-http + protocol: TCP + volumeMounts: + - mountPath: /etc/nginx/conf.d + readOnly: true + name: nginx-shop-prod + imagePullPolicy: Always + envFrom: + - configMapRef: + name: efc-shop-config-prod + volumes: + - name: nginx-shop-prod + configMap: + name: nginx-shop-prod + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: prod-environment + name: efc-shop-config-prod + labels: + app: efc-shop +data: + REACT_APP_PROD_API_URL: "http://efc-shop.k3s.semapp.lan/" + REACT_APP_DEV_API_URL: http://efc-shop.k3s.semapp.lan/ + + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: prod-environment + name: nginx-shop-prod +data: + default.conf: | + upstream backend { + server efc-backend-prod:5500; + } + + server { + listen 8501; + access_log /var/log/nginx/access.log; + charset utf-8; + client_max_body_size 1G; + + location / { + root /srv/efc-shop; + index index.html index.htm; + try_files $uri $uri /index.html =404; + } + + location ~ ^/api { + proxy_pass http://backend; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 300s; + proxy_send_timeout 300s; + send_timeout 300s; + } + + location /storage { + proxy_pass http://backend/storage; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 300s; + proxy_send_timeout 300s; + send_timeout 300s; + } + + error_page 404 =200 /index.html; + + add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + + expires off; + open_file_cache off; + sendfile off; + } + +--- +# EFC Service +apiVersion: v1 +kind: Service +metadata: + name: efc-shop-frontend-prod + namespace: prod-environment +spec: + selector: + app: efc-shop + ports: + - name: efc-http + port: 8501 + targetPort: efc-shop-http + type: NodePort + +--- + +# Ingress description +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + name: efc-shop-ingress + namespace: prod-environment + annotations: + kubernetes.io/ingress.class: "traefik" +spec: + rules: + - host: efc-shop.k3s.semapp.lan + http: + paths: + - path: / + backend: + serviceName: efc-shop-frontend-prod + servicePort: 8501 \ No newline at end of file diff --git a/02_hetzner/01_prod/efc/deployment.yaml b/02_hetzner/01_prod/efc/deployment.yaml new file mode 100644 index 0000000..603d9b6 --- /dev/null +++ b/02_hetzner/01_prod/efc/deployment.yaml @@ -0,0 +1,251 @@ +# Deployment description +apiVersion: apps/v1 +kind: Deployment +metadata: + name: efc-deployment + namespace: prod-environment + labels: + app: efc +spec: + strategy: + type: Recreate + replicas: 1 + selector: + matchLabels: + app: efc + template: + metadata: + labels: + app: efc + spec: + containers: + - name: efc-frontend + image: packages.semapp.lan:5000/efc-admin_frontend:prod + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "4" + ports: + - containerPort: 8500 + name: efc-http + protocol: TCP + volumeMounts: + - mountPath: /etc/nginx/conf.d + readOnly: true + name: efc-prod-nginx + imagePullPolicy: Always + envFrom: + - configMapRef: + name: efc-prod-config + - name: efc-backend + image: packages.semapp.lan:5000/efc-admin_backend:prod + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "4" + ports: + - containerPort: 5500 + name: efc-backend + protocol: TCP + imagePullPolicy: Always + volumeMounts: + - mountPath: /opt/efc/storage + name: efc-pv-prod + envFrom: + - configMapRef: + name: efc-prod-config + volumes: + - name: efc-prod-nginx + configMap: + name: efc-prod-nginx + - name: efc-pv-prod + persistentVolumeClaim: + claimName: efc-pvc-prod + +--- +# Persistent Volume Claim description +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: efc-pvc-prod + namespace: prod-environment + labels: + app: efc +spec: + storageClassName: longhorn + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: prod-environment + name: efc-prod-config + labels: + app: efc +data: + DJANGO_DB_ENGINE: "django.db.backends.postgresql_psycopg2" + DJANGO_DB_NAME: "efc-prod" + DJANGO_DB_USER: "efc-prod" + DJANGO_DB_PASSWORD: "O35iWjsO6RjvQulI2yti" + DJANGO_DB_HOST: "psql.semprod.local" + DJANGO_DB_PORT: "5432" + ALLOWED_HOSTS: '["*"]' + FRONTEND_URL: "http://efc.k3s.semapp.lan" + REACT_APP_PROD_API_URL: "http://efc.k3s.semapp.lan/" + REACT_APP_DEV_API_URL: http://efc.k3s.semapp.lan/ + PORT_FRONTEND: '8500' + SHOP_FRONTEND_URL: "http://efc-shop.k3s.semapp.lan" + SHOP_PORT_FRONTEND: '8501' + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: prod-environment + name: efc-prod-nginx +data: + default.conf: | + upstream backend { + server efc-backend-prod:5500; + } + + server { + listen 8500; + access_log /var/log/nginx/access.log; + charset utf-8; + client_max_body_size 1G; + + location / { + root /srv/efc; + index index.html index.htm; + try_files $uri $uri /index.html =404; + } + + location /administration { + root /srv/efc; + index index.html index.htm; + try_files $uri $uri /index.html =404; + } + + location ~ ^/api { + proxy_pass http://backend; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 300s; + proxy_send_timeout 300s; + send_timeout 300s; + } + + location /storage { + proxy_pass http://backend/storage; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 300s; + proxy_send_timeout 300s; + send_timeout 300s; + } + + location /admin { + proxy_pass http://backend/admin; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 300s; + proxy_send_timeout 300s; + send_timeout 300s; + } + + location /static-backend { + proxy_pass http://backend; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 300s; + proxy_send_timeout 300s; + send_timeout 300s; + } + + error_page 404 =200 /index.html; + + add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + + expires off; + open_file_cache off; + sendfile off; + } + +--- +# EFC Service +apiVersion: v1 +kind: Service +metadata: + name: efc-frontend-prod + namespace: prod-environment +spec: + selector: + app: efc + ports: + - name: efc-http + port: 8500 + targetPort: efc-http + type: NodePort + +--- +# EFC backend +apiVersion: v1 +kind: Service +metadata: + name: efc-backend-prod + namespace: prod-environment +spec: + selector: + app: efc + ports: + - name: efc-backend + port: 5500 + targetPort: efc-backend + type: NodePort +--- + +# Ingress description +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + name: efc-prod-ingress + namespace: prod-environment + annotations: + kubernetes.io/ingress.class: "traefik" +spec: + rules: + - host: efc.k3s.semapp.lan + http: + paths: + - path: / + backend: + serviceName: efc-frontend-prod + servicePort: 8500 \ No newline at end of file From ff73724a6d9ca9218e3626e4fea07c29fa05cae3 Mon Sep 17 00:00:00 2001 From: Antun Franjin Date: Mon, 15 Nov 2021 14:46:25 +0100 Subject: [PATCH 2/4] Final efc and efc-shop deployments. --- 02_hetzner/01_prod/efc-shop/deployment.yaml | 6 +++--- 02_hetzner/01_prod/efc/deployment.yaml | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/02_hetzner/01_prod/efc-shop/deployment.yaml b/02_hetzner/01_prod/efc-shop/deployment.yaml index de772f0..9eb49ee 100644 --- a/02_hetzner/01_prod/efc-shop/deployment.yaml +++ b/02_hetzner/01_prod/efc-shop/deployment.yaml @@ -54,8 +54,8 @@ metadata: labels: app: efc-shop data: - REACT_APP_PROD_API_URL: "http://efc-shop.k3s.semapp.lan/" - REACT_APP_DEV_API_URL: http://efc-shop.k3s.semapp.lan/ + REACT_APP_PROD_API_URL: "http://efc-shop.k8s.semprod.local" + REACT_APP_DEV_API_URL: "http://efc-shop.k8s.semprod.local" --- @@ -145,7 +145,7 @@ metadata: kubernetes.io/ingress.class: "traefik" spec: rules: - - host: efc-shop.k3s.semapp.lan + - host: efc-shop.k8s.semprod.local http: paths: - path: / diff --git a/02_hetzner/01_prod/efc/deployment.yaml b/02_hetzner/01_prod/efc/deployment.yaml index 603d9b6..52d7d74 100644 --- a/02_hetzner/01_prod/efc/deployment.yaml +++ b/02_hetzner/01_prod/efc/deployment.yaml @@ -101,11 +101,11 @@ data: DJANGO_DB_HOST: "psql.semprod.local" DJANGO_DB_PORT: "5432" ALLOWED_HOSTS: '["*"]' - FRONTEND_URL: "http://efc.k3s.semapp.lan" - REACT_APP_PROD_API_URL: "http://efc.k3s.semapp.lan/" - REACT_APP_DEV_API_URL: http://efc.k3s.semapp.lan/ + FRONTEND_URL: "http://efc-admin.k8s.semprod.local" + REACT_APP_PROD_API_URL: "http://efc-admin.k8s.semprod.local" + REACT_APP_DEV_API_URL: "http://efc-admin.k8s.semprod.local" PORT_FRONTEND: '8500' - SHOP_FRONTEND_URL: "http://efc-shop.k3s.semapp.lan" + SHOP_FRONTEND_URL: "http://efc-shop.k8s.semprod.local" SHOP_PORT_FRONTEND: '8501' --- @@ -242,10 +242,11 @@ metadata: kubernetes.io/ingress.class: "traefik" spec: rules: - - host: efc.k3s.semapp.lan + - host: efc-admin.k8s.semprod.local http: paths: - path: / backend: serviceName: efc-frontend-prod - servicePort: 8500 \ No newline at end of file + servicePort: 8500 + \ No newline at end of file From a268c8d2cab76c49d7cc272b2a5fb7d3ef0ba6a1 Mon Sep 17 00:00:00 2001 From: Antun Franjin Date: Tue, 16 Nov 2021 14:27:17 +0100 Subject: [PATCH 3/4] Add domain for inferno fulda shop. --- 02_hetzner/01_prod/efc-shop/deployment.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/02_hetzner/01_prod/efc-shop/deployment.yaml b/02_hetzner/01_prod/efc-shop/deployment.yaml index 9eb49ee..5ca30d4 100644 --- a/02_hetzner/01_prod/efc-shop/deployment.yaml +++ b/02_hetzner/01_prod/efc-shop/deployment.yaml @@ -146,6 +146,14 @@ metadata: spec: rules: - host: efc-shop.k8s.semprod.local + http: + paths: + - path: / + backend: + serviceName: efc-shop-frontend-prod + servicePort: 8501 + + - host: shop.inferno-fulda.de http: paths: - path: / From 8ed7227bf828e8c6a1f9dc0372ecbe52516914c7 Mon Sep 17 00:00:00 2001 From: Antun Franjin Date: Wed, 17 Nov 2021 16:28:37 +0100 Subject: [PATCH 4/4] Add react base url. --- 02_hetzner/01_prod/efc-shop/deployment.yaml | 1 + 02_hetzner/01_prod/efc/deployment.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/02_hetzner/01_prod/efc-shop/deployment.yaml b/02_hetzner/01_prod/efc-shop/deployment.yaml index 5ca30d4..ce99c11 100644 --- a/02_hetzner/01_prod/efc-shop/deployment.yaml +++ b/02_hetzner/01_prod/efc-shop/deployment.yaml @@ -56,6 +56,7 @@ metadata: data: REACT_APP_PROD_API_URL: "http://efc-shop.k8s.semprod.local" REACT_APP_DEV_API_URL: "http://efc-shop.k8s.semprod.local" + REACT_APP_BASE_URL: "http://efc-admin.k8s.semprod.local/" --- diff --git a/02_hetzner/01_prod/efc/deployment.yaml b/02_hetzner/01_prod/efc/deployment.yaml index 52d7d74..72398ad 100644 --- a/02_hetzner/01_prod/efc/deployment.yaml +++ b/02_hetzner/01_prod/efc/deployment.yaml @@ -104,6 +104,7 @@ data: FRONTEND_URL: "http://efc-admin.k8s.semprod.local" REACT_APP_PROD_API_URL: "http://efc-admin.k8s.semprod.local" REACT_APP_DEV_API_URL: "http://efc-admin.k8s.semprod.local" + REACT_APP_BASE_URL: "http://efc-admin.k8s.semprod.local/" PORT_FRONTEND: '8500' SHOP_FRONTEND_URL: "http://efc-shop.k8s.semprod.local" SHOP_PORT_FRONTEND: '8501'