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loxeU5WWm4zOVpQZEJKWHNSQ0xpK1hyWkF6WVhDeXlvRXo2QXJkSkdOS01iZ0gycjZkZmVxCmJJemdpUTJ6UXZKbFpTUVFOaWtzQ1FLQmdDZ3d6QW1VOEVYZEhSdHRFT1pYQlUzSG5CSmhnUDlQVXVIR0FXV1kKNC91dmpoWGJBaWVrSWJSWDl4dDNmaVFRK0hyZ0lmeEszRjI0NkswVGxLQVI1ZjdJV0FmN1htK2JteitPSEc0WAp2a2xUYTZJSnRwQnZJd2tTOVBFMUg3NXptNTRnVFcrR09Lb0srMTJibTR6TlpBMGhJeTlGUFZIY3ZLVVRwQUo4ClNkR0JBb0dBSEx0Sm5CMU5PNEVnTzZXdExRTVh0N0hySWJ1cDhlWmk4LzgyZ0MzNDIyQytvb0tJcllRMDdxU3cKbkJPTy9HME9CNHlkNnZDRTJ4NStUV1NTQ1lHZ0c1QThhSXY1cVA3NlJQNGhvdkdIeEcveTJ0Zm90dzVVdU9yaApuRldsVFA0VXJzOFBleWt2SzlhbzhyL1Q4Qm5QSUMxNlU2RU5ZdkFjMG1SbEZBMmoxR0E9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kms
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: kms
  replicas: 1 # tells deployment to run 1 pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      labels:
        app: kms
    spec:
      containers:
      - name: kms
        image: docker.io/kurento/kurento-media-server:latest
        # image: kurento/kurento-media-server:6.7.1-xenial
        imagePullPolicy: Always
        env:
          - name: "GST_DEBUG"
            # value: "Kurento*:5"
            # value: "5"
            # value: "3,sdp*:5,webrtc*:5,*dtls*:6"
            value: "4,*sdp*:6,*webrtc*:6,*endpoint*:6,agnosticbin:6,KurentoWebSocket*:6"
          - name: "KMS_ICE_TCP"
            value: "0"
          - name: "KMS_STUN_IP"
            value: ""
          - name: "KMS_STUN_PORT"
            value: ""
          - name: "KMS_TURN_URL"
            value: ""
          - name: "KMS_NETWORK_INTERFACES"
            value: "eth0"
          - name: "KMS_MIN_PORT"
            value: "10000"
          - name: "KMS_MAX_PORT"
            value: "20000"
          - name: "KMS_EXTERNAL_IPV4"
            value: ""
        ports:
        - containerPort: 8888
      # Uncomment this if you want to deploy a sidecar container to sniff traffic
      # - name: net-debug
      #   image: l7mp/net-debug:latest
      #   command: ["/bin/sh"]
      #   args: ["-c", "while true; do echo hello; sleep 10;done"]

---
apiVersion: v1
kind: Service
metadata:
  name: kms
  namespace: default
  labels:
    app: kms
spec:
  selector:
    app: kms
  ports:
    - port: 8888
      protocol: TCP
      name: kms-port
    - port: 9999
      protocol: UDP
      name: kms-media-plane-port


# WebRTC application server
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webrtc-server
  # namespace: stunner
spec:
  selector:
    matchLabels:
      app: webrtc-server
  replicas: 1
  template:
    metadata:
      labels:
        app: webrtc-server
    spec:
      containers:
      - name: webrtc-server
        image: docker.io/l7mp/kurento-one2one-call-server
        imagePullPolicy: Always
        # image: localhost/l7mp/kurento-one2one-call-server
        # imagePullPolicy: Never
        # command: [ "sleep" ]
        # args: [ "infinity" ]
        command: ["npm"]
        args: ["start", "--", "--as_uri=https://0.0.0.0:8443", "--ws_uri=ws://kms.default.svc.cluster.local:8888/kurento"]
        ports:
        - containerPort: 8443
        # TURN server config to return to the user
        env:
          - name: STUNNER_AUTH_ADDR
            value: "stunner-auth.stunner-system.svc.cluster.local"
          - name: STUNNER_AUTH_PORT
            value: "8088"
          # - name: STUNNER_NAMESPACE
          #   value: "stunner"
          # - name: STUNNER_GATEWAY
          #   value: "udp-gateway"
          # - name: STUNNER_LISTENER
          #   value: "udp-listener"
        volumeMounts:
          - name: webrtc-server-tls
            mountPath: "/app/keys"
            readOnly: true
      volumes:
        - name: webrtc-server-tls
          secret:
            secretName: webrtc-server-secret
            items:
              - key: tls.crt
                path: server.crt
              - key: tls.key
                path: server.key

---
apiVersion: v1
kind: Service
metadata:
  name: webrtc-server
  # namespace: stunner
  labels:
    app: webrtc-server
spec:
  type: LoadBalancer
  selector:
    app: webrtc-server
  ports:
    - port: 8443
      protocol: TCP
      name: webrtc-server-port
