janus部署在kubernetes教程

kubernetes 版本 v1.21.0

coturn部署yaml内容

Service.yaml

apiVersion: v1
kind: Service
metadata:
  name: stun-turn
  namespace: janus
  labels:
    app: stun-turn
spec:
  selector:
    app: stun-turn
  ports:
  - name: stun
    protocol: TCP
    port: 3478
    targetPort: 3478
  - name: stun-udp
    protocol: UDP
    port: 3478
    targetPort: 3478
  type: ClusterIP

DaemonSet.yaml文件内容

bash 复制代码
apiVersion: v1
kind: Service
metadata:
  name: stun-turn
  namespace: janus
  labels:
    app: stun-turn
spec:
  selector:
    app: stun-turn
  ports:
  - name: stun
    protocol: TCP
    port: 3478
    targetPort: 3478
  - name: stun-udp
    protocol: UDP
    port: 3478
    targetPort: 3478
  type: ClusterIP
qinzhao@jumper02:~/janus/deployment/coturn$ cat DaemonSet.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: stun-turn
  namespace: janus
spec:
  selector:
    matchLabels:
      app: stun-turn
  template:
    metadata:
      labels:
        app: stun-turn
    spec:
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      containers:
        - name: stun-turn
          image: instrumentisto/coturn
          imagePullPolicy: IfNotPresent
          env:
            - name: TZ
              value: "UTC"
      tolerations:
        - effect: NoExecute
          key: node.kubernetes.io/not-ready
          operator: Exists
          tolerationSeconds: 0
        - effect: NoExecute
          key: node.kubernetes.io/unreachable
          operator: Exists
          tolerationSeconds: 0

namespace yaml文件

bash 复制代码
apiVersion: v1
kind: Namespace
metadata:
  labels:
    kubernetes.io/metadata.name: janus
  name: janus
spec:
  finalizers:
  - kubernetes

janus

Service.yaml

bash 复制代码
apiVersion: v1
kind: Service
metadata:
  name: janus-svc
  namespace: janus
spec:
  selector:
    app: janus
  ports:
  - name: http
    port: 8088
    targetPort: 8088
  - name: websocket
    port: 8188
    targetPort: 8188
  - name: webrtc
    port: 7088
    targetPort: 7088
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: janus-stream
  namespace: janus
  labels:
    app: janus
spec:
  selector:
    app: janus
  ports:
  - name: stream1-video
    protocol: UDP
    port: 9000
    targetPort: 9000
  - name: stream1-data
    protocol: UDP
    port: 9001
    targetPort: 9001
  - name: stream1-audio
    protocol: UDP
    port: 9002
    targetPort: 9002
  - name: stream2-video
    protocol: UDP
    port: 9003
    targetPort: 9003
  - name: stream2-data
    protocol: UDP
    port: 9004
    targetPort: 9004
  - name: stream2-audio
    protocol: UDP
    port: 9005
    targetPort: 9005
  type: ClusterIP

ConfigMap.yaml

bash 复制代码
kind: ConfigMap
metadata:
  name: janus-config
  namespace: janus
apiVersion: v1
data:
  janus.jcfg: |-
    general: {
      configs_folder = "/usr/local/etc/janus"
      plugins_folder = "/usr/local/lib/janus/plugins"
      transports_folder = "/usr/local/lib/janus/transports"
      events_folder = "/usr/local/lib/janus/events"
      loggers_folder = "/usr/local/lib/janus/loggers"

      debug_level = 4

      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"
      ]
    }

    nat: {
        stun_server = "stun-turn"
        stun_port = 3478
    }
  janus.plugin.streaming.jcfg: |-
    general: {
      threads = 8
    }

    stream1: {
      type = "rtp"
      id = 1
      description = "streamingroom-1"
      audio = true
      video = true
      data = true
      videopt = 100
      videortpmap = "VP8/90000"
      videoport = 9000
      dataport = 9001
      audioport = 9002
      audiopt = 111
    }

    stream2: {
      type = "rtp"
      id = 2
      description = "streamingroom2"
      audio = true
      video = true
      data = true
      videopt = 100
      videortpmap = "VP8/90000"
      videoport = 9003
      dataport = 9004
      audioport = 9005
      audiopt = 111
    }

DaemonSet.yaml文件

bash 复制代码
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: janus
  namespace: janus
spec:
  selector:
    matchLabels:
      app: janus
  template:
    metadata:
      labels:
        app: janus
    spec:
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      volumes:
        - name: janus-config
          configMap:
            name: janus-config
      containers:
        - name: janus
          image: canyan/janus-gateway:0.10.7
          imagePullPolicy: IfNotPresent
          env:
            - name: TZ
              value: "UTC"
          volumeMounts:
            - name: janus-config
              mountPath: /usr/local/etc/janus/janus.jcfg
              subPath: janus.jcfg
            - name: janus-config
              mountPath: /usr/local/etc/janus/janus.plugin.streaming.jcfg
              subPath: janus.plugin.streaming.jcfg
      tolerations:
        - effect: NoExecute
          key: node.kubernetes.io/not-ready
          operator: Exists
          tolerationSeconds: 0
        - effect: NoExecute
          key: node.kubernetes.io/unreachable
          operator: Exists
          tolerationSeconds: 0

nginx-janus

Service.yaml

bash 复制代码
apiVersion: v1
kind: Service
metadata:
  name: nginx-janus-svc
  namespace: janus
spec:
  selector:
    app: nginx-janus
  ports:
  - name: http
    port: 8088
    targetPort: 8088
  - name: websocket
    port: 8188
    targetPort: 8188
  - name: webrtc
    port: 7088
    targetPort: 7088
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-janus-stats-svc
spec:
  selector:
    app: nginx-janus
  ports:
  - name: http
    port: 3000
    targetPort: 3000
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-janus-stream
  labels:
    app: nginx-janus
spec:
  selector:
    app: nginx-janus
  ports:
  - name: stream1-video
    protocol: UDP
    port: 9000
    targetPort: 9000
  - name: stream1-data
    protocol: UDP
    port: 9001
    targetPort: 9001
  - name: stream1-audio
    protocol: UDP
    port: 9002
    targetPort: 9002
  - name: stream2-video
    protocol: UDP
    port: 9003
    targetPort: 9003
  - name: stream2-data
    protocol: UDP
    port: 9004
    targetPort: 9004
  - name: stream2-audio
    protocol: UDP
    port: 9005
    targetPort: 9005
  type: ClusterIP

Configmap.yaml

bash 复制代码
kind: ConfigMap
metadata:
  name: nginx-janus-config
  namespace: janus
apiVersion: v1
data:
  nginx.conf: |-
        worker_processes  10;

        events {
            worker_connections  1024;
        }

        http{
            server {
                listen 3000;
                location /nginx_status {
                stub_status on;
                access_log   off;
                allow 0.0.0.0;
                }
            }
        }

        stream {
            server {
                listen 8188;
                proxy_pass janus-ws;
            }

            upstream janus-ws{
                server janus-svc:8188;
            }

            server {
                listen 8088;
                proxy_pass janus-http;
            }

            upstream janus-http{
                server janus-svc:8088;
            }

            server {
                listen 7088;
                proxy_pass janus-webrtc;
            }

            upstream janus-webrtc{
                server janus-svc:7088;
            }

            server {
                listen 9000 udp;
                proxy_pass streamingroom1v;
            }

            upstream streamingroom1v{
                server janus-stream:9000;
            }

            server {
                listen 9001 udp;
                proxy_pass streamingroom1d;
            }

            upstream streamingroom1d{
                server janus-stream:9001;
            }

            server {
                listen 9002 udp;
                proxy_pass streamingroom1a;
            }

            upstream streamingroom1a{
                server janus-stream:9002;
            }

            server {
                listen 9003 udp;
                proxy_pass streamingroom2v;
            }

            upstream streamingroom2v{
                server janus-stream:9003;
            }

            server {
                listen 9004 udp;
                proxy_pass streamingroom2d;
            }

            upstream streamingroom2d{
                server janus-stream:9004;
            }

            server {
                listen 9005 udp;
                proxy_pass streamingroom2a;
            }

            upstream streamingroom2a{
                server janus-stream:9005;
            }
        }

Deployment.yaml

bash 复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-janus
  namespace: janus
spec:
  selector:
    matchLabels:
      app: nginx-janus
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-janus
    spec:
      volumes:
        - name: nginx-janus-config
          configMap:
            name: nginx-janus-config
      containers:
        - name: janus
          image: nginx
          imagePullPolicy: IfNotPresent
          env:
            - name: TZ
              value: "UTC"
          volumeMounts:
            - name: nginx-janus-config
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
      tolerations:
        - effect: NoExecute
          key: node.kubernetes.io/not-ready
          operator: Exists
          tolerationSeconds: 0
        - effect: NoExecute
          key: node.kubernetes.io/unreachable
          operator: Exists
          tolerationSeconds: 0

janus-ingress.yaml

bash 复制代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: janus
  namespace: janus
spec:
  ingressClassName: kong
  rules:
  - host: janus-webrtc.domain.com
    http:
      paths:
      - backend:
          service:
            name: nginx-janus-svc
            port:
              number: 7088
        path: /
        pathType: ImplementationSpecific
  - host: janus-websocket.domain.com
    http:
      paths:
      - backend:
          service:
            name: nginx-janus-svc
            port:
              number: 8188
        path: /
        pathType: ImplementationSpecific
  - host: janus-http.domain.com
    http:
      paths:
      - backend:
          service:
            name: nginx-janus-svc
            port:
              number: 8088
        path: /
        pathType: ImplementationSpecific

通过以上文件 使用kubectl 进行apply 就可以部署成功了

参考:

https://bugraoz93.medium.com/active-passive-highly-availability-janus-gateway-on-kubernetes-2189256e5525

相关推荐
JunLan~7 小时前
Rocky Linux 系统安装/部署 Docker
linux·docker·容器
小袁搬码11 小时前
Windows中指定路径安装DockerDesktop
windows·docker·容器·docker desktop
qq_3129201111 小时前
docker 部署 kvm 图形化管理工具 WebVirtMgr
运维·docker·容器
踏雪Vernon11 小时前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
linux·docker·容器·harmonyos
条纹布鲁斯12 小时前
dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
docker·kubernetes
CP-DD14 小时前
Docker 容器化开发 应用
运维·docker·容器
老司机张师傅15 小时前
【微服务实战之Docker容器】第七章-Dockerfile解析
容器·dockerfile·虚悬镜像·docker学习
登云时刻16 小时前
Kubernetes集群外连接redis集群和使用redis-shake工具迁移数据(一)
redis·kubernetes·bootstrap
运维&陈同学16 小时前
【zookeeper03】消息队列与微服务之zookeeper集群部署
linux·微服务·zookeeper·云原生·消息队列·云计算·java-zookeeper
吴半杯17 小时前
gateway漏洞(CVE-2022-22947)
docker·kubernetes·gateway