Expose a deployment to external access by using a load balancer service.
Outcomes
Use load balancer services to expose the video streams that the application produces.
Access the video streams with a media player.
Realize that external factors can cause a load balancer to fail.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start non-http-lb
Instructions
Log in as the developer user, and list the YAML resource manifests for the video streaming application in the ~/DO280/labs/non-http-lb directory.
Log in to the cluster as the developer user.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Create the non-http-lb project.
[student@workstation ~]$ oc new-project non-http-lb
Now using project "non-http-lb" on server ...
...output omitted...Change to the ~/DO280/labs/non-http-lb directory.
[student@workstation ~]$ cd ~/DO280/labs/non-http-lb
[student@workstation non-http-lb]$List the contents of the directory. The YAML resource manifests represent three instances of the video streaming application.
[student@workstation non-http-lb]$ ls -l
total 12
-rw-rw-r--. 1 student student 1561 Jun 21 16:29 virtual-rtsp-1.yaml
-rw-rw-r--. 1 student student 1563 Jun 21 16:29 virtual-rtsp-2.yaml
-rw-rw-r--. 1 student student 1565 Jun 21 16:21 virtual-rtsp-3.yamlEach deployment emulates the video stream from a security camera on port 8554.
| Deployment | Video stream | Location | Image | |
|---|---|---|---|---|
virtual-rtsp-1
| Camera 1 | Downtown |
| |
virtual-rtsp-2
| Camera 2 | Roundabout |
| |
virtual-rtsp-3
| Camera 3 | Intersection |
|
Deploy the first instance of the application, and expose the video stream from the downtown camera by using a load balancer service.
Create the first instance of the video stream deployment. This application produces the video stream of the downtown camera.
[student@workstation non-http-lb]$ oc apply -f virtual-rtsp-1.yaml
deployment.apps/virtual-rtsp-1 createdWait until the pod is running and the deployment is ready.
Press Ctrl+C to exit the watch command.
[student@workstation non-http-lb]$watch oc get deployments,podsEvery 2.0s: oc get deployments,pods workstation: Wed Jun 21 16:25:26 2023 NAMEREADYUP-TO-DATE AVAILABLE AGE deployment.apps/virtual-rtsp-11/11 1 59s NAME READYSTATUSRESTARTS AGE pod/virtual-rtsp-1-98cd84d79a-qhn9r 1/1Running0 59s
Create a load balancer service to expose the first deployment.
[student@workstation non-http-lb]$ oc expose deployment/virtual-rtsp-1 \
--type=LoadBalancer --target-port=8554
service/virtual-rtsp-1 exposedGet the external IP address of the load balancer service.
[student@workstation non-http-lb]$oc get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE virtual-rtsp-1 LoadBalancer 172.30.4.18192.168.50.208554:32170/TCP 59s
Verify that you can connect to the external IP address of the load balancer service on port 8554.
[student@workstation non-http-lb]$ nc -vz 192.168.50.20 8554
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.50.20:8554.
Ncat: 0 bytes sent, 0 bytes received in 0.01 secondsOpen the URL in the media player to confirm that the video stream of the downtown camera is working correctly.
rtsp://192.168.50.20:8554/stream
[student@workstation non-http-lb]$ totem rtsp://192.168.50.20:8554/stream
...output omitted...Close the media player window after confirming that the video stream works correctly.
![]() |
Deploy the remaining instances of the video stream application. Expose the video streams from the roundabout and intersection cameras by using a load balancer service. Understand that the classroom is configured to provide only two IP addresses.
Create the second instance of the video stream deployment. This application produces the video stream of the roundabout camera.
[student@workstation non-http-lb]$ oc apply -f virtual-rtsp-2.yaml
deployment.apps/virtual-rtsp-2 createdCreate the third instance of the video stream deployment. This application produces the video stream of the intersection camera.
[student@workstation non-http-lb]$ oc apply -f virtual-rtsp-3.yaml
deployment.apps/virtual-rtsp-3 createdWait until the pods are running and the deployments are ready.
Press Ctrl+C to exit the watch command.
[student@workstation non-http-lb]$watch oc get deployments,podsEvery 2.0s: oc get deployments,pods workstation: Wed Jun 21 16:30:33 2023 NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/virtual-rtsp-1 1/1 1 1 5m deployment.apps/virtual-rtsp-21/11 1 60s deployment.apps/virtual-rtsp-31/11 1 30s NAME READY STATUS RESTARTS AGE pod/virtual-rtsp-1-98cd84d79a-qhn9r 1/1 Running 0 5m pod/virtual-rtsp-2-769b5bcb89-r8csp 1/1Running0 60s pod/virtual-rtsp-3-6cdb9f7ffb-g6d9d 1/1Running0 30s
Create a load balancer service to expose the second deployment.
[student@workstation non-http-lb]$ oc expose deployment/virtual-rtsp-2 \
--type=LoadBalancer --target-port=8554
service/virtual-rtsp-2 exposedCreate a load balancer service to expose the third deployment.
[student@workstation non-http-lb]$ oc expose deployment/virtual-rtsp-3 \
--type=LoadBalancer --target-port=8554
service/virtual-rtsp-3 exposedGet the external IP address of the second load balancer service.
[student@workstation non-http-lb]$oc get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) ... virtual-rtsp-1 LoadBalancer 172.30.94.188 192.168.50.20 8554:32325/TCP ... virtual-rtsp-2 LoadBalancer 172.30.15.148192.168.50.218554:31640/TCPvirtual-rtsp-3 LoadBalancer 172.30.228.35
<pending>8554:32089/TCP
The second load balancer service has an associated external IP address. | |
No IP address is assigned to the third load balancer, and it is displayed as |
Open the URL in the media player to confirm that the video stream of the roundabout camera is working correctly.
rtsp://192.168.50.21:8554/stream
[student@workstation non-http-lb]$ totem rtsp://192.168.50.21:8554/stream
...output omitted...Close the media player window after confirming that the video stream works correctly.
![]() |
Delete the first service to reallocate the IP address to the third service, and view the video stream of the intersection camera.
Delete the first service to release the assigned IP address.
[student@workstation non-http-lb]$ oc delete service/virtual-rtsp-1
service "virtual-rtsp-1" deletedVerify that the third service has an assigned external IP address.
[student@workstation non-http-lb]$oc get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) ... virtual-rtsp-2 LoadBalancer 172.30.15.148 192.168.50.21 8554:31640/TCP ...virtual-rtsp-3LoadBalancer 172.30.228.35192.168.50.208554:32089/TCP
Open the URL in the media player to confirm that the video stream of the intersection camera is working correctly.
rtsp://192.168.50.20:8554/stream
[student@workstation non-http-lb]$ totem rtsp://192.168.50.20:8554/stream
...output omitted...Close the media player window after confirming that the video stream works correctly.
![]() |
Clean up the resources.
Change to the student HOME directory.
[student@workstation non-http-lb]$ cd
[student@workstation ~]$Delete all the services in the namespace.
[student@workstation ~]$ oc delete services --all
service "virtual-rstp-2" deleted
service "virtual-rstp-3" deletedDelete all the deployments in the namespace.
[student@workstation ~]$ oc delete deployments --all
deployment.apps "virtual-rtsp-1" deleted
deployment.apps "virtual-rtsp-2" deleted
deployment.apps "virtual-rtsp-3" deletedDelete the non-http-lb project.
[student@workstation ~]$ oc delete project/non-http-lb
project.project.openshift.io "non-http-lb" deleted