Skip to content

v4_EN_K8S

winlin edited this page Feb 27, 2020 · 24 revisions

HOME > EN > K8S

K8S

Cloud+Docker+K8S enable everyone to build live video streaming cluster and service.

Why should you use k8s to build your SRS cluster?

  • Simple: It's really simple and convenient, let's figure it out by QuickStart.
  • Declarative deployment: We declare a desired SRS cluster and it'll always be there, without starting and migrating service, watchdog and SLB configuration.
  • Expand easily: K8S allows you to expand infrastructure automatically, and you can expand your business cluster easily by change the number of Pods.
  • Rolling Update: K8S allows deployment update, rollback and gray release with zero downtime.
  • XXX: Coming soon...

This tutorial highlights how to build SRS cluster for a variety of scenarios in ACK(AlibabaCloud Container Service for Kubernetes).

  1. Quick Start: Deployment a SRS origin server in ACK.
  2. SRS Shares Volume with Nginx: SRS is able to deliver simple HTTP content, or work with Nginx, SRS delivers RTMP/HTTP-FLV and write HLS to a share volume, then Nginx reads and delivers HLS.
  3. SRS Edge Cluster for High Concurrency Streaming: SRS edge cluster, which is configured and updated automatically, to provide services for huge players.
  4. SRS Origin Cluster for a Large Number of Streams: SRS origin cluster is designed to serve a large number of streams.
  5. SRS Cluster Update, Rollback, Gray Release with Zero Downtime: K8S allows deployment update, rollback and gray release with zero downtime.
  6. Useful Tips
    1. Create K8S Cluster in ACK: Create your own k8s cluster in ACK.
    2. Publish Demo Streams to SRS: Publish the demo streams to SRS.
    3. Cleanup For DVR/HLS Temporary Files: Remove the temporary files for DVR/HLS.
    4. Use One SLB and EIP for All Streaming Service: Use one SLB for RTMP/HTTP-FLV/HLS streaming service.
    5. Build SRS Origin Cluster as Deployment: Rather than StatefulSet, we can also use deployment to build Origin Cluster.
    6. Managing Compute Resources for Containers: Resource requests and limits, and how pods requests are scheduled and limits are run.
  7. XXX: Coming soon...

Quick Start

Assumes you have access to a k8s cluster, you can easily create one in Aliyun, say the following command should succeed:

kubectl cluster-info

Let's take a look at a single SRS origin server in k8s.

SRS: Single Origin Server

Step 1: Create a k8s deployment for SRS origin server:

cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: srs-deployment
  labels:
    app: srs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: srs
  template:
    metadata:
      labels:
        app: srs
    spec:
      containers:
      - name: srs
        image: ossrs/srs:3
        ports:
        - containerPort: 1935
        - containerPort: 1985
        - containerPort: 8080
EOF

Step 2: Create a k8s service which exposing live video streaming service by SLB with EIP:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  name: srs-service
spec:
  type: LoadBalancer
  selector:
    app: srs
  ports:
  - name: srs-service-1935-1935
    port: 1935
    protocol: TCP
    targetPort: 1935
  - name: srs-service-1985-1985
    port: 1985
    protocol: TCP
    targetPort: 1985
  - name: srs-service-8080-8080
    port: 8080
    protocol: TCP
    targetPort: 8080
EOF

Here we create SLB and EIP automatically, you can also buy from AlibabaCloud to provide service, for example:

  • SLB ID: lb-2xxyfvpao868wzfvcmx7b
  • EIP: 28.170.32.118

Then you can use your intranet SLB:

metadata:
  annotations:
    service.beta.kubernetes.io/alicloud-loadbalancer-address-type: intranet
    service.beta.kubernetes.io/alicloud-loadbalancer-force-override-listeners: "true"
    service.beta.kubernetes.io/alicloud-loadbalancer-id: lb-2xxyfvpao868wzfvcmx7b

Remark: The SLB should be in the same VPC with your K8S cluster.

Step 3: Done, you could get the EIP and play with SRS now.

Please use kubectl get svc/srs-service to get the EIP:

NAME          TYPE           CLUSTER-IP      EXTERNAL-IP
srs-service   LoadBalancer   172.21.12.131   28.170.32.118

Then you can publish and play with 28.170.32.118:

ACK: SRS Done

SRS Shares Volume with Nginx

Coming soon...

SRS Edge Cluster for High Concurrency Streaming

Coming soon...

SRS Origin Cluster for a Large Number of Streams

Coming soon...

SRS Cluster Update, Rollback, Gray Release with Zero Downtime

Coming soon...

Useful Tips

There are some useful tips for you.

  1. Create K8S Cluster in ACK: Create your own k8s cluster in ACK.
  2. Publish Demo Streams to SRS: Publish the demo streams to SRS.
  3. Use One SLB and EIP for All Streaming Service: Use one SLB for RTMP/HTTP-FLV/HLS streaming service.
  4. Build SRS Origin Cluster as Deployment: Rather than StatefulSet, we can also use deployment to build Origin Cluster.
  5. Managing Compute Resources for Containers: Resource requests and limits, and how pods requests are scheduled and limits are run.

Create K8S Cluster in ACK

Coming soon...

Publish Demo Streams to SRS

Coming soon...

Use One SLB for All Streaming Service

Coming soon...

Build SRS Origin Cluster as Deployment

Coming soon...

Managing Compute Resources for Containers

Coming soon...

Winlin 2020.02

Welcome to SRS wiki!

SRS 5.0 wiki

Please select your language:

SRS 4.0 wiki

Please select your language:

SRS 3.0 wiki

Please select your language:

SRS 2.0 wiki

Please select your language:

SRS 1.0 wiki

Please select your language:

Clone this wiki locally