# Janus Gateway 
apiVersion: v1
kind: ConfigMap
metadata:
  name: janus-gateway
data:
  janus.jcfg: |
    general: {
        configs_folder = "@confdir@"			
        plugins_folder = "@plugindir@"			
        transports_folder = "@transportdir@"	
        events_folder = "@eventdir@"			
        loggers_folder = "@loggerdir@"			
        debug_level = 4							
        admin_secret = "janusoverlord"	
        protected_folders = [
            "/bin",
            "/boot",
            "/dev",
            "/etc",
            "/initrd",
            "/lib",
            "/lib32",
            "/lib64",
            "/proc",
            "/sbin",
            "/sys",
            "/usr",
            "/var",
            "/opt/janus/bin",
            "/opt/janus/etc",
            "/opt/janus/include",
            "/opt/janus/lib",
            "/opt/janus/lib32",
            "/opt/janus/lib64",
            "/opt/janus/sbin"
    }
    certificates: {
    }
    media: {
    }
    nat: {
        nice_debug = false
        ice_ignore_list = "vmnet"
    plugins: {
        
    }
    transports: {
        
    }
    loggers: {
        
    }
    events: {
    }
---
apiVersion: v1
kind: Service
metadata:
  name: janus-gateway
  labels:
    app.kubernetes.io/name: janus-gateway
    app.kubernetes.io/instance: janus
    app.kubernetes.io/version: "v1.2.4"
spec:
  type: ClusterIP
  ports:
    - port: 8088
      targetPort: 8088
      protocol: TCP
      name: http
    - port: 8188
      targetPort: 8188
      protocol: TCP
      name: websocket
  selector:
    app.kubernetes.io/name: janus-gateway
    app.kubernetes.io/instance: janus
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: janus-gateway
  labels:
    app.kubernetes.io/name: janus-gateway
    app.kubernetes.io/instance: janus
    app.kubernetes.io/version: "v1.2.4"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: janus-gateway
      app.kubernetes.io/instance: janus
  template:
    metadata:
      labels:
        app.kubernetes.io/name: janus-gateway
        app.kubernetes.io/instance: janus
    spec:
      terminationGracePeriodSeconds: 18000 # 5 hours
      containers:
        - name: janus-gateway
          image: "l7mp/janus-gateway:v1.2.4"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8088
              protocol: TCP
            - name: websocket
              containerPort: 8188
              protocol: TCP
---
# Janus Web Demos 
apiVersion: v1
kind: ConfigMap
metadata:
  name: janus-web
data:
  settings.js: |
    var server = "wss://server-ingressserviceip.nip.io"
    var iceServers = [{urls: "turn:stunner_ip:3478?transport=udp", username: "user-1", credential: "pass-1"}]
---
apiVersion: v1
kind: Service
metadata:
  name: janus-web
  labels:
    app.kubernetes.io/name: janus-web
    app.kubernetes.io/instance: janus-web
    app.kubernetes.io/version: "v1.2.4"
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: janus-web
    app.kubernetes.io/instance: janus-web
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: janus-web
  labels:
    app.kubernetes.io/name: janus-web
    app.kubernetes.io/instance: janus-web
    app.kubernetes.io/version: "v1.2.4"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: janus-web
      app.kubernetes.io/instance: janus-web
  template:
    metadata:
      labels:
        app.kubernetes.io/name: janus-web
        app.kubernetes.io/instance: janus-web
    spec:
      containers:
        - name: janus-web
          image: "l7mp/janus-web:latest"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          volumeMounts:
            - name: config
              mountPath: /usr/share/nginx/html/demos/settings.js
              subPath: settings.js
      volumes:
      - name: config
        configMap:
          name: janus-web
          items:
          - key: settings.js
            path: settings.js
---
# Ingress for both Janus Gateway and Janus Web Demos
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: janus-web-demos
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-origin: "*"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
      - client-ingressserviceip.nip.io
      - server-ingressserviceip.nip.io
    secretName: janus-web-secret-tls
  rules:
  - host: server-ingressserviceip.nip.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: janus-gateway
            port:
              number: 8188
  - host: client-ingressserviceip.nip.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: janus-web
            port:
              number: 80
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    email: info@l7mp.io
    server: https://acme-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      name: letsencrypt-secret-prod
    solvers:
    - http01:
        ingress:
          class: nginx
---