From a771793fcf5ea5b997176112c52d23a4138c1d09 Mon Sep 17 00:00:00 2001 From: hangy Date: Fri, 21 Sep 2018 16:35:41 +0200 Subject: [PATCH] Add Kubernetes configuration for the frontend.Aadd Kubernetes configuration for the frontend. --- docker/kubernetes/data-pvc.yaml | 12 ++++ docker/kubernetes/frontend-conf.yaml | 67 ++++++++++++++++++++++ docker/kubernetes/frontend-deployment.yaml | 42 ++++++++++++++ docker/kubernetes/frontend-service.yaml | 16 ++++++ docker/kubernetes/images-pvc.yaml | 12 ++++ docker/kubernetes/ingress.yaml | 18 ++++++ 6 files changed, 167 insertions(+) create mode 100644 docker/kubernetes/data-pvc.yaml create mode 100644 docker/kubernetes/frontend-conf.yaml create mode 100644 docker/kubernetes/frontend-deployment.yaml create mode 100644 docker/kubernetes/frontend-service.yaml create mode 100644 docker/kubernetes/images-pvc.yaml create mode 100644 docker/kubernetes/ingress.yaml diff --git a/docker/kubernetes/data-pvc.yaml b/docker/kubernetes/data-pvc.yaml new file mode 100644 index 0000000000000..ca617b7b8b61e --- /dev/null +++ b/docker/kubernetes/data-pvc.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: po-data + labels: + app: po +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi diff --git a/docker/kubernetes/frontend-conf.yaml b/docker/kubernetes/frontend-conf.yaml new file mode 100644 index 0000000000000..e7f3e137774cc --- /dev/null +++ b/docker/kubernetes/frontend-conf.yaml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: po-frontend-config + labels: + app: po + component: frontend +data: + nginx.conf: | + server { + listen 80; + listen [::]:80; + + # Product Opener needs a root domain + a wildcard for all subdomains + server_name po.992d6328c7ec48169146.westeurope.aksapp.io *.po.992d6328c7ec48169146.westeurope.aksapp.io; + + root /opt/product-opener/html/; + + gzip on; + gzip_min_length 1000; + + # Add index.php to the list if you are using PHP + index index.html index.htm index.nginx-debian.html; + + location ~* \.(eot|ttf|woff|woff2)$ { + add_header Access-Control-Allow-Origin *; + } + + location ~ ^/images/products/ { + add_header Link "; rel='license'; title='CC-BY-SA 3.0'"; + } + + location ~ ^/(favicon.ico) { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + # Static files are served directly by NGINX + + location ~ ^/(.well-known|images|js|css|rss|data|files|resources|foundation|bower_components)/ { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + location = /robots.txt { + try_files $uri $uri/ =404; + } + + # Dynamically generated files and CGI scripts are passed + # to the Apache + mod_perl server running on the backend container + + location / { + 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_pass http://example.org/cgi/display.pl?; + } + + location /cgi/ { + 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_pass http://example.org; + } + } diff --git a/docker/kubernetes/frontend-deployment.yaml b/docker/kubernetes/frontend-deployment.yaml new file mode 100644 index 0000000000000..ab54d6f1e47b0 --- /dev/null +++ b/docker/kubernetes/frontend-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: po-frontend + labels: + app: po + component: frontend +spec: + replicas: 1 + template: + metadata: + labels: + app: po + component: frontend + spec: + containers: + - name: po-frontend + image: openfoodfacts/productopener-frontend + lifecycle: + postStart: + exec: + command: + - '/bin/sh' + - '-c' + - > + cp -Lrf /tmp/nginx.conf /etc/nginx/conf.d/default.conf; + nginx -s reload; touch /var/log/nginx/conf.done + ports: + - containerPort: 80 + volumeMounts: + - name: frontend-config + mountPath: "/tmp/nginx.conf" + subPath: nginx.conf + - name: product-images + mountPath: "/opt/product-opener/html/images/products/" + volumes: + - name: frontend-config + configMap: + name: po-frontend-config + - name: product-images + persistentVolumeClaim: + claimName: po-images diff --git a/docker/kubernetes/frontend-service.yaml b/docker/kubernetes/frontend-service.yaml new file mode 100644 index 0000000000000..69c64b8732525 --- /dev/null +++ b/docker/kubernetes/frontend-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: po-frontend + labels: + app: po + component: frontend +spec: + type: LoadBalancer + ports: + - port: 80 + protocol: TCP + name: http + selector: + app: po + component: frontend diff --git a/docker/kubernetes/images-pvc.yaml b/docker/kubernetes/images-pvc.yaml new file mode 100644 index 0000000000000..5a13b6462ed29 --- /dev/null +++ b/docker/kubernetes/images-pvc.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: po-images + labels: + app: po +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi diff --git a/docker/kubernetes/ingress.yaml b/docker/kubernetes/ingress.yaml new file mode 100644 index 0000000000000..b87fd885d001e --- /dev/null +++ b/docker/kubernetes/ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: po + labels: + app: po +spec: + backend: + serviceName: po-frontend + servicePort: 80 + rules: + - host: "*.po.992d6328c7ec48169146.westeurope.aksapp.io" + http: + paths: + - path: / + backend: + serviceName: po-frontend + servicePort: 80