# source https://github.com/GaiZhenbiao/ChuanhuChatGPT
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: home-apps
  name: ch-chatgpt-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nfs-client
  resources:
    requests:
      storage: 5Gi
# ---
# apiVersion: v1
# kind: PersistentVolumeClaim
# metadata:
#   namespace: home-apps
#   name: config-chatgpt-pvc
# spec:
#   accessModes:
#     - ReadWriteOnce
#   storageClassName: nfs-client
#   resources:
#     requests:
#       storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: ch-chatgpt
  namespace: home-apps
spec:
  ports:
    - port: 7860
      targetPort: 7860
  selector:
    app: ch-chatgpt
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ch-chatgpt
spec:
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: ch-chatgpt
  replicas: 1
  template:
    metadata:
      labels:
        app: ch-chatgpt
    spec:
      volumes:
        - name: config
          persistentVolumeClaim:
            claimName: ch-chatgpt-pvc
      containers:
        - name: ch-chatgpt
          image: tuchuanhuhuhu/chuanhuchatgpt:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 7860
          env: []
          resources:
            requests:
              cpu: 200m
              memory: 512Mi
            limits:
              cpu: 500m
              memory: 1024Mi
          volumeMounts:
            - name: config
              mountPath: /app/history
              subPath: history
            - name: config
              mountPath: /app/config.json
              subPath: config.json

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ch-chatgpt-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://id.junv.me/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://id.junv.me/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
  tls:
    - hosts:
        - chat.junv.me
      secretName: chatgpt-tls
  rules:
    - host: chat.junv.me
      http:
        paths:
          - backend:
              service:
                name: ch-chatgpt
                port:
                  number: 7860
            path: /
            pathType: Prefix
