Bookmark this page

Guided Exercise: Load Balancer Services

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

  1. 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.

    1. 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...
    2. Create the non-http-lb project.

      [student@workstation ~]$ oc new-project non-http-lb
      Now using project "non-http-lb" on server ...
      ...output omitted...
    3. Change to the ~/DO280/labs/non-http-lb directory.

      [student@workstation ~]$ cd ~/DO280/labs/non-http-lb
      [student@workstation non-http-lb]$
    4. 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.yaml
    5. Each deployment emulates the video stream from a security camera on port 8554.

      Deployment Video stream Location Image
      virtual-rtsp-1 Camera 1Downtown
      virtual-rtsp-2 Camera 2Roundabout
      virtual-rtsp-3 Camera 3Intersection
  2. Deploy the first instance of the application, and expose the video stream from the downtown camera by using a load balancer service.

    1. 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 created
    2. Wait 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,pods
      Every 2.0s: oc get deployments,pods        workstation: Wed Jun 21 16:25:26 2023
      
      NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
      deployment.apps/virtual-rtsp-1   1/1     1            1           59s
      
      NAME                                  READY   STATUS    RESTARTS   AGE
      pod/virtual-rtsp-1-98cd84d79a-qhn9r   1/1     Running   0          59s
    3. 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 exposed
    4. Get the external IP address of the load balancer service.

      [student@workstation non-http-lb]$ oc get services
      NAME            TYPE          CLUSTER-IP   EXTERNAL-IP    PORT(S)         AGE
      virtual-rtsp-1  LoadBalancer  172.30.4.18  192.168.50.20  8554:32170/TCP  59s
    5. 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 seconds
    6. Open 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.

  3. 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.

    1. 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 created
    2. Create 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 created
    3. Wait 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,pods
      Every 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-2   1/1     1            1           60s
      deployment.apps/virtual-rtsp-3   1/1     1            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/1     Running   0          60s
      pod/virtual-rtsp-3-6cdb9f7ffb-g6d9d   1/1     Running   0          30s
    4. 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 exposed
    5. Create 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 exposed
    6. Get the external IP address of the second load balancer service.

      [student@workstation non-http-lb]$ oc get services
      NAME            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.148  192.168.50.21  8554:31640/TCP   1
      virtual-rtsp-3  LoadBalancer  172.30.228.35  <pending>      8554:32089/TCP   2

      1

      The second load balancer service has an associated external IP address.

      2

      No IP address is assigned to the third load balancer, and it is displayed as <pending> because all available load balancer IP addresses are in use. The MetalLB operator in the classroom uses the IPAddressPools configuration to restrict the available load balancer IP addresses to 192.168.50.20 and 192.168.50.21.

    7. 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.

  4. Delete the first service to reallocate the IP address to the third service, and view the video stream of the intersection camera.

    1. 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" deleted
    2. Verify that the third service has an assigned external IP address.

      [student@workstation non-http-lb]$ oc get services
      NAME            TYPE          CLUSTER-IP     EXTERNAL-IP    PORT(S)          ...
      virtual-rtsp-2  LoadBalancer  172.30.15.148  192.168.50.21  8554:31640/TCP   ...
      virtual-rtsp-3  LoadBalancer  172.30.228.35  192.168.50.20  8554:32089/TCP   1

      1

      The IP address is now allocated to the third service.

    3. 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.

  5. Clean up the resources.

    1. Change to the student HOME directory.

      [student@workstation non-http-lb]$ cd
      [student@workstation ~]$
    2. Delete all the services in the namespace.

      [student@workstation ~]$ oc delete services --all
      service "virtual-rstp-2" deleted
      service "virtual-rstp-3" deleted
    3. Delete 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" deleted
    4. Delete the non-http-lb project.

      [student@workstation ~]$ oc delete project/non-http-lb
      project.project.openshift.io "non-http-lb" deleted

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish non-http-lb

Revision: do280-4.14-08d11e1