apiVersion: apps/v1
kind: Deployment
metadata:
  name: qdrant
spec:
  replicas: 1
  selector:
    matchLabels:
      app: qdrant
  template:
    metadata:
      labels:
        app: qdrant
    spec:
      nodeSelector:
        kubernetes.io/hostname: server-3
      tolerations:
        - key: "node"
          operator: "Equal"
          value: "special"
          effect: "NoSchedule"
        - key: node-role.kubernetes.io/master
          operator: Equal
          value: ""
          effect: NoSchedule
        - key: node-role.kubernetes.io/control-plane
          operator: Equal
          value: ""
          effect: NoSchedule
      containers:
        - name: qdrant
          image: mirror.gcr.io/qdrant/qdrant:v1.16-unprivileged
          ports:
            - containerPort: 6333
            - containerPort: 6334
          env:
            - name: TZ
              value: "Australia/Melbourne"
            - name: QDRANT__SERVICE__ENABLE_TLS
              value: "0"
            - name: QDRANT__LOG_LEVEL
              value: INFO
            - name: QDRANT__SERVICE__API_KEY
              valueFrom:
                secretKeyRef:
                  name:  qdrant-api-key
                  key: key
            - name: QDRANT__SERVICE__JWT_RBAC
              value: "true"
          volumeMounts:
            - name: data
              mountPath: "/qdrant/storage"
          resources:
            limits:
              cpu: "1"
              memory: "1Gi"
            requests:
              cpu: "200m"
              memory: "256Mi"
          securityContext:
            privileged: false
            runAsGroup: 1000
            # fsGroup: 1000
            runAsUser: 1000
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: qdrant-local-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: qdrant-lb
  namespace: db
  annotations:
    metallb.universe.tf/loadBalancerIPs: 192.168.1.202
spec:
  selector:
    app: qdrant
  ports:
    - protocol: TCP
      port: 6333
      targetPort: 6333
      name: web
    - protocol: TCP
      port: 6334
      targetPort: 6334
      name: grpc
  type: LoadBalancer
  externalIPs:
    - 192.168.1.202

---
apiVersion: v1
kind: Service
metadata:
  name: qdrant
spec:
  selector:
    app: qdrant
  ports:
    - protocol: TCP
      port: 6333
      targetPort: 6333
      name: web
    - protocol: TCP
      port: 6334
      name: grpc
      targetPort: 6334

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: qdrant-ingress
  namespace: db
  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://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:
    - qdrant.junv.cc
    secretName: qdrant-tls
  rules:
  - host: qdrant.junv.cc
    http:
      paths:
      - backend:
          service:
            name: qdrant
            port:
              number: 6333
        path: /
        pathType: Prefix
