From 4948906e36966a218ffa760557205470b0da296c Mon Sep 17 00:00:00 2001 From: hutzlerhe <helmut.hutzler@th-nuernberg.de> Date: Sat, 8 Oct 2022 14:15:10 +0200 Subject: [PATCH] New complexe Ingressroute sample --- IngressRoute/ingressRoute_nginx.yaml | 34 +++++++++++++++++ IngressRoute/ingressRoute_whoami.yaml | 14 +++++++ IngressRoute/nginx-deploy-blue.yaml | 52 ++++++++++++++++++++++++++ IngressRoute/nginx-deploy-green.yaml | 53 +++++++++++++++++++++++++++ IngressRoute/test-ingressroutes.sh | 28 ++++++++++++++ IngressRoute/whoami-deploy.yaml | 41 +++++++++++++++++++++ 6 files changed, 222 insertions(+) create mode 100644 IngressRoute/ingressRoute_nginx.yaml create mode 100644 IngressRoute/ingressRoute_whoami.yaml create mode 100644 IngressRoute/nginx-deploy-blue.yaml create mode 100644 IngressRoute/nginx-deploy-green.yaml create mode 100755 IngressRoute/test-ingressroutes.sh create mode 100644 IngressRoute/whoami-deploy.yaml diff --git a/IngressRoute/ingressRoute_nginx.yaml b/IngressRoute/ingressRoute_nginx.yaml new file mode 100644 index 0000000..fff4d46 --- /dev/null +++ b/IngressRoute/ingressRoute_nginx.yaml @@ -0,0 +1,34 @@ +apiVersion: traefik.containo.us/v1alpha1 +kind: Middleware +metadata: + name: nginx-strip-path-prefix +spec: + stripPrefix: + prefixes: + - /nginx-green + - /nginx-blue +--- +apiVersion: traefik.containo.us/v1alpha1 +kind: IngressRoute +metadata: + name: ingressroute-nginx +spec: + entryPoints: + - websecure + routes: + - match: Host(`dev-storage.informatik.fh-nuernberg.de`) && Path(`/nginx-green`) + kind: Rule + middlewares: + - name: nginx-strip-path-prefix + services: + - name: nginx-service-green + port: 8080 + - match: Host(`dev-storage.informatik.fh-nuernberg.de`) && Path(`/nginx-blue`) + kind: Rule + middlewares: + - name: nginx-strip-path-prefix + services: + - name: nginx-service-blue + port: 8080 + + diff --git a/IngressRoute/ingressRoute_whoami.yaml b/IngressRoute/ingressRoute_whoami.yaml new file mode 100644 index 0000000..839e6a2 --- /dev/null +++ b/IngressRoute/ingressRoute_whoami.yaml @@ -0,0 +1,14 @@ +apiVersion: traefik.containo.us/v1alpha1 +kind: IngressRoute +metadata: + name: ingressroute-who-svc +spec: + entryPoints: + - websecure + routes: + - match: Host(`dev-storage.informatik.fh-nuernberg.de`) && Path(`/who`) + kind: Rule + services: + - name: whoami-svc + port: 80 + diff --git a/IngressRoute/nginx-deploy-blue.yaml b/IngressRoute/nginx-deploy-blue.yaml new file mode 100644 index 0000000..5f2575d --- /dev/null +++ b/IngressRoute/nginx-deploy-blue.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: nginx + name: nginx-deploy-blue +spec: + replicas: 1 + selector: + matchLabels: + app: nginx-blue + template: + metadata: + labels: + app: nginx-blue + spec: + volumes: + - name: webdata + emptyDir: {} + initContainers: + - name: web-content + image: busybox + volumeMounts: + - name: webdata + mountPath: "/webdata" + command: ["/bin/sh", "-c", 'echo "<h1>I am <font color=blue>BLUE</font></h1>" > /webdata/index.html'] + containers: + - image: nginx + name: nginx + volumeMounts: + - name: webdata + mountPath: "/usr/share/nginx/html" + +--- +apiVersion: v1 +kind: Service +metadata: + name: nginx-service-blue +spec: + type: ClusterIP + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 80 + - name: https + protocol: TCP + port: 8443 + targetPort: 443 + selector: + app: nginx-blue + diff --git a/IngressRoute/nginx-deploy-green.yaml b/IngressRoute/nginx-deploy-green.yaml new file mode 100644 index 0000000..10899c1 --- /dev/null +++ b/IngressRoute/nginx-deploy-green.yaml @@ -0,0 +1,53 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: nginx + name: nginx-deploy-green +spec: + replicas: 1 + selector: + matchLabels: + app: nginx-green + template: + metadata: + labels: + app: nginx-green + spec: + volumes: + - name: webdata + emptyDir: {} + initContainers: + - name: web-content + image: busybox + volumeMounts: + - name: webdata + mountPath: "/webdata" + command: ["/bin/sh", "-c", 'echo "<h1>I am <font color=green>GREEN</font></h1>" > /webdata/index.html'] + containers: + - image: nginx + name: nginx + volumeMounts: + - name: webdata + mountPath: "/usr/share/nginx/html" + +--- +apiVersion: v1 +kind: Service +metadata: + name: nginx-service-green +spec: + type: ClusterIP + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 80 + - name: https + protocol: TCP + port: 8443 + targetPort: 443 + selector: + app: nginx-green + + diff --git a/IngressRoute/test-ingressroutes.sh b/IngressRoute/test-ingressroutes.sh new file mode 100755 index 0000000..f6c4530 --- /dev/null +++ b/IngressRoute/test-ingressroutes.sh @@ -0,0 +1,28 @@ +#!/bin/bash +ingresshost="dev-storage.informatik.fh-nuernberg.de" +echo "Setup for ingressRoute host: ${ingresshost}" +kubectl delete namespace testing +kubectl create namespace testing +# +# Create Pods / Serives +kubectl -n testing apply -f nginx-deploy-green.yaml +kubectl -n testing apply -f nginx-deploy-blue.yaml +kubectl -n testing apply -f whoami-deploy.yaml +# +# Create ingressRoutes +kubectl -n testing apply -f ingressRoute_whoami.yaml +kubectl -n testing apply -f ingressRoute_nginx.yaml + +# Validate with curl - wait untill pods are availabe +# +sleep curl -v --insecure https://dev-storage.informatik.fh-nuernberg.de/who +5 +# +kubectl -n testing get all +# +curl -v --insecure https://dev-storage.informatik.fh-nuernberg.de/nginx-green +curl -v --insecure https://dev-storage.informatik.fh-nuernberg.de/nginx-blue +curl -v --insecure https://dev-storage.informatik.fh-nuernberg.de/who + +echo "Test following URL in your browser " +echo diff --git a/IngressRoute/whoami-deploy.yaml b/IngressRoute/whoami-deploy.yaml new file mode 100644 index 0000000..ba56d86 --- /dev/null +++ b/IngressRoute/whoami-deploy.yaml @@ -0,0 +1,41 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + name: whoami-pod + labels: + app: whoami--deployment +spec: + replicas: 1 + selector: + matchLabels: + app: whoami + template: + metadata: + labels: + app: whoami + spec: + containers: + - name: whoami-container + image: containous/whoami + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: whoami-svc + labels: + app: whoami +spec: + type: NodePort + ports: + - port: 80 + name: whoami + targetPort: 80 + # Optional field + # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) + nodePort: 30331 + protocol: TCP + selector: + app: whoami + -- GitLab