Deployment of a Serverless Media Function

Jonas Rydholm Birmé, Streaming Video Specialist, Eyevinn Technology

What is Kubernetes?

For those not already familiar with Kubernetes it is a system that can be described as the conductor or orchestrator for running Docker containers on a cluster of nodes. It can handle the replication of a containers running on multiple nodes for example to handle more traffic and loads. Assume that you are not using a container orchestrator that would for example mean that you manually need to administer that if a container on one node goes down another container on a different node is started. However, Kubernetes does not manage the actual infrastructure that nodes are running on.

Media Function Pod

A Pod represents processes running on your cluster and encapsulates an application’s container (in our case our media function), storage resources and a unique network IP. It is possible to use a Pod directly it is more common to let Kubernetes manage the pods using a Controller. But for the purpose of understanding let us first create and run a Pod directly for our media function. I will later in this article describe on how to use a Controller to create and run this pod.

apiVersion: v1
kind: Pod
metadata:
name: function-probe
labels:
app: function-probe
spec:
containers:
- name: function-probe
image: function-probe:0.1.0
ports:
- containerPort: 8080
protocol: TCP
$ kubectl apply -f pod.yaml
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
function-probe 1/1 Running 0 2m8s
$ kubectl port-forward media-function-probe 8080:8080
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
11a9777508b8 2323f847dee3 "npm start" 5 minutes ago Up 5 minutes k8s_function-probe_function-probe_default_cef1dd27-2e51-11ea-b11f-025000000001_0
$ kubectl delete -f pod.yaml

Media Function Controller

As mentioned it is not very common to manually create and run Pods like this and instead we will use a Controller. A Controller handles replication and rollout of Pods, and if a Node fails the Controller can replace the Pod by scheduling a replicate on a different Node. To create a Pod a Controller uses a Pod Template which is quite similar to the Pod definition we created before. We will use a specific type of Controller called Deployment as we want to rollout replications of our media function in the background at a controlled rate. This is how our configuration for the Controller could look like.

apiVersion: apps/v1
kind: Deployment
metadata:
name: function-probe-deployment
labels:
app: function-probe
spec:
replicas: 2
selector:
matchLabels:
app: function-probe
template:
metadata:
labels:
app: function-probe
spec:
containers:
- name: function-probe
image: function-probe:0.1.0
ports:
- containerPort: 8080
protocol: TCP
$ kubectl apply -f deployment.yaml
deployment.apps/function-probe-deployment created
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
function-probe-deployment-767fd65bc7-jr8cl 1/1 Running 0 34s
function-probe-deployment-767fd65bc7-scvg5 1/1 Running 0 34s
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
function-probe-deployment 2/2 2 2 13m

spec:
containers:
- name: function-probe
image: function-probe:0.1.1

Media Function Service

Now we have a set of Pods deployed and we need a way to expose this set of Pods. In Kubernetes we create a Service to achieve this. The set of Pods targeted by a Service is determined by a selector and we will use the label we defined for the media function pods. This gives us a Service definition that looks like this:

apiVersion: v1
kind: Service
metadata:
name: media-function-probe
spec:
type: NodePort
selector:
app: function-probe
ports:
- port: 8080
nodePort: 30000
protocol: TCP
name: http
$ kubectl apply -f service.yaml
service/media-function-probe created
$ kubectl describe svc media-function-probe

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eyevinn Technology

Eyevinn Technology

We are consultants sharing the passion for the technology for a media consumer of the future.