apiVersion: apps/v1
kind: Deployment
metadata:
  name: ${APP_NAME}-livekit
  namespace: ${K8S_NAMESPACE}
  labels:
    app: ${APP_NAME}-livekit
    app.kubernetes.io/name: tia-livekit
    app.kubernetes.io/part-of: tia
spec:
  replicas: ${LIVEKIT_REPLICAS}
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: ${APP_NAME}
  template:
    metadata:
      labels:
        app: ${APP_NAME}
        app.kubernetes.io/name: tia-livekit
        app.kubernetes.io/part-of: tia
    spec:
      hostAliases:
      - ip: ${REDIS_IP}
        hostnames:
        - ${REDIS_HOST}
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        runAsGroup: 1000
        fsGroup: 1000
      volumes:
        - name: config-volume
          configMap:
            name: ${APP_NAME}-livekit-config
      containers:
        - name: ${APP_NAME}-livekit
          image: ${IMAGE_REPOSITORY_LIVEKIT}:${IMAGE_TAG}
          imagePullPolicy: IfNotPresent
          args:
            - "--config"
            - "/etc/livekit/livekit.yaml"
          envFrom:
            - secretRef:
                name: ${APP_NAME}-api-secrets
          volumeMounts:
            - name: config-volume
              mountPath: /etc/livekit
              readOnly: true
          ports:
            - name: signal
              containerPort: 7880
            - name: rtc-tcp
              containerPort: 7881
            - name: rtc-udp
              containerPort: 7882
              protocol: UDP
          readinessProbe:
            tcpSocket:
              port: 7880
            initialDelaySeconds: 20
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          livenessProbe:
            tcpSocket:
              port: 7880
            initialDelaySeconds: 30
            periodSeconds: 20
            timeoutSeconds: 5
            failureThreshold: 3
          resources:
            requests:
              cpu: "${CPU_LIVEKIT_REQ}"
              memory: "${MEM_LIVEKIT_REQ}"
            limits:
              cpu: "${CPU_LIVEKIT_LIM}"
              memory: "${MEM_LIVEKIT_LIM}"
---
apiVersion: v1
kind: Service
metadata:
  name: ${APP_NAME}-livekit
  namespace: ${K8S_NAMESPACE}
spec:
  type: NodePort
  selector:
    app.kubernetes.io/name: tia-livekit
  ports:
    - name: signal
      port: 7880
      targetPort: 7880
    - name: rtc-tcp
      port: 7881
      targetPort: 7881
    - name: rtc-udp
      port: 7882
      targetPort: 7882
      protocol: UDP
