apiVersion: v1
kind: PersistentVolume
metadata:
  name: hey-search-local-pv
  labels:
    type: local
    name: hey-search
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage
  local:
    path: /mnt/k8s/hey-search
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - server-3
---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: home-apps
  name: hey-search-local-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: "local-storage"
  resources:
    requests:
      storage: 5Gi
---
# https://github.com/wahyd4/hey-search
apiVersion: v1
kind: Service
metadata:
  name: hey-search
  namespace: home-apps
spec:
  ports:
  - port: 8000
    targetPort: 8000
  selector:
    app: hey-search
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hey-search
spec:
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: hey-search
  replicas: 1
  template:
    metadata:
      labels:
        app: hey-search
    spec:
      imagePullSecrets:
        - name: github-image-pull-secret
      containers:
        - name: hey-search
          image: ghcr.io/wahyd4/hey-search:latest
          imagePullPolicy: Always
          env:
            - name: TZ
              value: Australia/Melbourne
          ports:
            - containerPort: 8000
          volumeMounts:
            - name: data
              mountPath: /app/data
          resources:
            limits:
              cpu: "2"
              memory: "1Gi"
            requests:
              cpu: "0.4"
              memory: "256Mi"
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: hey-search-local-pvc
---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hey-search-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/proxy-body-size: 200m
    nginx.ingress.kubernetes.io/whitelist-source-range: "192.168.1.0/24"
spec:
  tls:
  - hosts:
    - sear.junv.cc
    secretName: hey-search-tls
  rules:
  - host: sear.junv.cc
    http:
      paths:
      - backend:
          service:
            name: hey-search
            port:
              number: 8000
        path: /
        pathType: Prefix


---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hey-search-short-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/proxy-body-size: 200m
    nginx.ingress.kubernetes.io/auth-url: "https://pass.junv.cc/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://pass.junv.cc/oauth2/start?rd=https://$host$escaped_request_uri"
spec:
  tls:
  - hosts:
    - s.junv.cc
    secretName: s-tls
  rules:
  - host: s.junv.cc
    http:
      paths:
      - backend:
          service:
            name: hey-search
            port:
              number: 8000
        path: /
        pathType: Prefix
