---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: golink
  labels:
    app: golink

spec:
  replicas: 1
  selector:
    matchLabels:
      app: golink
  template:
    metadata:
      labels:
        app: golink
    spec:
      containers:
      - name: golink
        image: docker.dezendorf.net/golink
        ports:
        - name: web
          containerPort: 80
        volumeMounts:
        - name: golinks-volume
          mountPath: /gradle/app/database
      volumes:
      - name: golinks-volume
        persistentVolumeClaim:
          claimName: golinks-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: golink

spec:
  type: ClusterIP
  ports:
    - name: web
      port: 80 
      targetPort: 80

  selector:
    app: golink
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: golinks-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 2Gi
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: golink-ingress-route
  namespace: default
spec:
  entryPoints:
    - web
  routes:
  - match: ((Host(`gogo`)||Host(`gogo.dezendorf.net`)||Host(`gogo`)||Host(`gogor.dezendorf.net`))) && PathPrefix(`/_`)
    kind: Rule
    priority: 20
    middlewares:
    - name: httpsgofqdn
    services:
    - name: golink
      port: 80

  - match: (Host(`gogo.dezendorf.net`)||Host(`gogor.dezendorf.net`))||Host(`gogo`)
    priority: 10
    kind: Rule
    services:
    - name: golink
      port: 80

---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: golink-websecure-route
  namespace: default
spec:
  entryPoints:
    - websecure
  routes:
  - match: (Host(`gogo.dezendorf.net`)||Host(`gogor.dezendorf.net`))
    kind: Rule
    middlewares:
    - name: authelia
    services:
    - name: golink
      port: 80
  tls:
    certResolver: myresolver

---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: httpsgofqdn
spec:
  redirectRegex:
    regex: "^http(s)?://(gogo(.dezendorf.net)?)/_(.*)$"
    replacement: "https://gogo.dezendorf.net/_${4}"
