apiVersion: v1
kind: Namespace
metadata:
  name: cube-video2slides
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: video2slides
  namespace: cube-video2slides
  labels:
    app: video2slides
spec:
  replicas: 1
  # 用了 hostPath + 单副本，重建时先杀旧的再起新的，避免两个 pod 抢同一目录
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: video2slides
  template:
    metadata:
      labels:
        app: video2slides
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
        - name: video2slides
          image: registry.famzheng.me/mochi/video2slides:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: http
          env:
            - name: VIDEO2SLIDES_DATA_DIR
              value: "/data"
            - name: VIDEO2SLIDES_DIST_DIR
              value: "/dist"
          volumeMounts:
            - name: data
              mountPath: /data
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 1
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 5
            periodSeconds: 15
          resources:
            requests:
              cpu: 50m
              memory: 128Mi
            limits:
              # ffmpeg 抽帧 + image 解码比较吃 CPU/内存，给足
              cpu: "2"
              memory: 1Gi
      volumes:
        - name: data
          hostPath:
            # 上传的视频 + 抽出的帧落在节点本地盘，pod 重启不丢（单节点 k3s）
            path: /var/lib/cube/video2slides
            type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: video2slides
  namespace: cube-video2slides
spec:
  selector:
    app: video2slides
  ports:
    - name: http
      port: 80
      targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: video2slides
  namespace: cube-video2slides
spec:
  ingressClassName: traefik
  rules:
    - host: video2slides.famzheng.me
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: video2slides
                port:
                  number: 80
