Skip to content
Snippets Groups Projects
Commit 4948906e authored by hutzlerhe's avatar hutzlerhe
Browse files

New complexe Ingressroute sample

parent 29fed885
No related branches found
No related tags found
No related merge requests found
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
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
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
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
#!/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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment