Bookmark this page

Lab: Expose non-HTTP/SNI Applications

Expose applications to external access without using an ingress controller.

Outcomes

  • Expose a non-http application to external access by using the LoadBalancer type service.

  • Configure a network attachment definition for an isolated network.

  • Make an application accessible outside the cluster on an isolated network by using an existing node network interface.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that the cluster API is reachable and configures the MetalLB operator to provide a single IP address, 192.168.50.20, for the load balancer services.

[student@workstation ~]$ lab start non-http-review

Instructions

  1. Deploy the virtual-rtsp application to a new non-http-review-rtsp project as the developer user with the developer password, and verify that the virtual-rtsp pod is running.

    The application consists of the ~/DO280/labs/non-http-review/virtual-rtsp.yaml file.

    1. Log in to your OpenShift cluster as the developer user with the developer password.

      [student@workstation ~]$ oc login -u developer -p developer \
        https://api.ocp4.example.com:6443
      Login successful.
      ...output omitted...
    2. Change to the ~/DO280/labs/non-http-review directory.

      [student@workstation ~]$ cd ~/DO280/labs/non-http-review
    3. Create a non-http-review-rtsp project.

      [student@workstation non-http-review]$ oc new-project non-http-review-rtsp
      Now using project "non-http-review-rtsp" on server ...
      ...output omitted...
    4. Use the oc create command to create the virtual-rtsp deployment by using the virtual-rtsp.yaml file.

      [student@workstation non-http-review]$ oc create -f virtual-rtsp.yaml
      deployment.apps/virtual-rtsp created
    5. List the deployments and pods. Wait for the virtual-rtsp pod to be ready. Press Ctrl+C to exit the watch command.

      [student@workstation non-http-review]$ watch oc get deployments,pods
      NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
      deployment.apps/virtual-rtsp   1/1     1            1           21s
      
      NAME                                READY   STATUS    RESTARTS   AGE
      pod/virtual-rtsp-54d8d6b57d-6jsvm   1/1     Running   0          21s
  2. Expose the virtual-rtsp deployment by using the LoadBalancer service.

    1. Create a load balancer service for the virtual-rtsp deployment.

      [student@workstation non-http-review]$ oc expose deployment/virtual-rtsp \
        --name=virtual-rtsp-loadbalancer --type=LoadBalancer
      service/virtual-rtsp-loadbalancer exposed
    2. Retrieve the external IP address of the virtual-rtsp-loadbalancer service.

      [student@workstation non-http-review]$ oc get svc/virtual-rtsp-loadbalancer
      NAME                       TYPE          ...  EXTERNAL-IP    PORT(S)
      virtual-rtsp-loadbalancer  LoadBalancer  ...  192.168.50.20  8554:32570/TCP

      The virtual-rtsp-loadbalancer has the 192.168.50.20 external IP address.

  3. Access the virtual-rtsp application by using the URL in the media player. Run the totem rtsp://EXTERNAL-IP:8554/stream command to play the stream in the media player.

    1. Open the URL in the media player to confirm that the video stream is working correctly.

      rtsp://192.168.50.20:8554/stream

      [student@workstation non-http-review]$ totem rtsp://192.168.50.20:8554/stream
      ...output omitted...

      Close the media player window after confirming that the video stream works correctly.

  4. Deploy the nginx deployment to a new non-http-review-nginx project as the developer user with the developer password, and verify that the nginx pod is running. The application consists of the ~/DO280/labs/non-http-review/nginx.yaml file.

    Important

    The exercise is using an HTTP application as a stand-in for testing connectivity to an external network.

    1. Create a non-http-review-nginx project.

      [student@workstation non-http-review]$ oc new-project non-http-review-nginx
      Now using project "non-http-review-nginx" on server ...
      ...output omitted...
    2. Use the oc apply command to create the nginx deployment by using the nginx.yaml file.

      [student@workstation non-http-review]$ oc apply -f nginx.yaml
      deployment.apps/nginx created
    3. List the deployments and pods. Wait for the nginx pod to be ready. Press Ctrl+C to exit the watch command.

      [student@workstation non-http-review]$ watch oc get deployments,pods
      NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
      deployment.apps/nginx   1/1     1            1           53s
      
      NAME                        READY   STATUS    RESTARTS   AGE
      pod/nginx-649779cbd-d6sbv   1/1     Running   0          53s
  5. Configure a network attachment definition for the ens4 interface, so that the isolated network can be attached to a pod.

    The master01 node has two Ethernet interfaces. The ens3 interface is the main network interface of the cluster. The ens4 interface is an additional network interface for exercises that require an additional network. The ens4 interface is attached to a 192.168.51.0/24 network, with the 192.168.51.10 IP address.

    You can modify the ~/DO280/labs/non-http-review/network-attachment-definition.yaml file to configure a network attachment definition by using the following parameters:

    Parameter Value
    name custom
    type host-device
    device ens4
    ipam.type static
    ipam.addresses {"address": "192.168.51.10/24"}
    1. Log in to your OpenShift cluster as the admin user with the redhatocp password.

      [student@workstation non-http-review]$ oc login -u admin -p redhatocp \
        https://api.ocp4.example.com:6443
      Login successful.
      ...output omitted...
    2. Edit the ~/DO280/labs/non-http-review/network-attachment-definition.yaml file. Use the custom name, the host-device type, and the ens4 device. Configure IP address management to use the static type, with the 192.168.51.10/24 address.

      apiVersion: k8s.cni.cncf.io/v1
      kind: NetworkAttachmentDefinition
      metadata:
        name: custom
      spec:
        config: |-
          {
            "cniVersion": "0.3.1",
            "name": "custom",
            "type": "host-device",
            "device": "ens4",
            "ipam": {
              "type": "static",
              "addresses": [
                {"address": "192.168.51.10/24"}
              ]
            }
          }
    3. Use the oc create command to create the network attachment definition.

      [student@workstation non-http-review]$ oc create -f \
        network-attachment-definition.yaml
      networkattachmentdefinition.k8s.cni.cncf.io/custom created
  6. The nginx application does not contain any services, so the application is not accessible outside the pod network.

    Assign the ens4 network interface exclusively to the nginx pod, by using the custom network attachment definition. Edit the nginx deployment to add the k8s.v1.cni.cncf.io/networks annotation with the custom value as the developer user with the developer password.

    1. Log in to the OpenShift cluster as the developer user with the developer password.

      [student@workstation non-http-review]$ oc login -u developer -p developer \
        https://api.ocp4.example.com:6443
      Login successful.
      
      ...output omitted...
    2. Edit the ~/DO280/labs/non-http-review/nginx.yaml file to add the k8s.v1.cni.cncf.io/networks annotation with the custom value.

      ...output omitted...
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: nginx
        strategy:
          type: Recreate
        template:
          metadata:
            labels:
              app: nginx
            annotations:
              k8s.v1.cni.cncf.io/networks: custom
          spec:
            containers:
      ...output omitted...
    3. Use the oc apply command to add the annotation.

      [student@workstation non-http-review]$ oc apply -f nginx.yaml
      deployment.apps/nginx configured
    4. Wait for the nginx pod to be ready. Press Ctrl+C to exit the watch command.

      [student@workstation non-http-review]$ watch oc get deployments,pods
      NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
      deployment.apps/nginx   1/1     1            1           34m
      
      NAME                        READY   STATUS    RESTARTS   AGE
      pod/nginx-6f45d9f89-wp2gg   1/1     Running   0          53s
    5. Examine the k8s.v1.cni.cncf.io/networks-status annotation in the pod.

      [student@workstation ~]$ oc get pod nginx-6f45d9f89-wp2gg \
        -o jsonpath='{.metadata.annotations.k8s\.v1\.cni\.cncf\.io/network-status}'
      [{
          "name": "ovn-kubernetes",
          "interface": "eth0",
          "ips": [
              "10.8.0.82"
          ],
          "mac": "0a:58:0a:08:00:52",
          "default": true,
          "dns": {}
      },{
          "name": "non-http-review-nginx/custom",
          "interface": "net1",
          "ips": [
              "192.168.51.10"
          ],
          "mac": "52:54:00:01:33:0a",
          "dns": {}
      }]

      Note

      The period is the JSONPath field access operator. Normally, you use the period to access parts of the resource, such as in the .metadata.annotations JSONPath expression. To access fields that contain periods with JSONPath, you must escape the periods with a backslash (\).

  7. Verify that you can access the nginx application from the utility machine by using the following URL:

    http://isolated-network-IP-address:8080

    1. Use the ssh command to connect to the utility machine.

      [student@workstation non-http-review]$ ssh utility
      ...output omitted...
      [student@utility ~]$
    2. Verify that the nginx application is accessible. Use the IP address on the isolated network to access the nginx application.

      [student@utility ~]$ curl 'http://192.168.51.10:8080/'
      <html>
        <body>
          <h1>Hello, world from nginx!</h1>
        </body>
      </html>
    3. Exit the SSH session to go back to the workstation machine.

      [student@utility ~]$ exit
      logout
      Connection to utility closed.
      [student@workstation non-http-review]$
  8. Verify that you cannot access the nginx application from the workstation machine, because the workstation machine cannot access the isolated network.

    1. Verify that the nginx application is not accessible from the workstation machine.

      [student@workstation non-http-review]$ curl 'http://192.168.51.10:8080/'
      curl: (7) Failed to connect to 192.168.51.10 port 8080: Connection timed out
    2. Change to the student HOME directory.

      [student@workstation non-http-review]$ cd
      [student@workstation ~]$

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade non-http-review

Finish

As the student user 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-review

Revision: do280-4.14-08d11e1