Working with Virtual Machines and Applications

Introduction

This section of our lab is dedicated to the Day-2 operations that many administrators would need to perform when working with virtual machines in their OpenShift Virtualization environment. We will make use of the understanding we have developed throughout this roadshow of how VMs operate in an OpenShift environment, and use those skills to complete the tasks in this section. In this particular case, we are going to work with the three virtual machines that we imported from VMware vSphere earlier in this roadshow, and we are going to make some minor configuration changes to enable the applications hosted on those servers to be accessed as they now run in OpenShift Virtualization. To accomplish this, we will expose our applications using the service/route method that is the default when making use of the OpenShift SDN pod network so that the application is reachable from outside of the cluster.

Exposing an Application with a Service/Route

By default, virtual machines are connected to the SDN, which is a convenient and easy way to give them access to the rest of the network, but can be challenging for the virtual machines, and other pods in the OpenShift cluster, to find and connect to the virtualized applications. To solve this, we will use a Service to balance connections across the two Windows-based web servers, and create a DNS entry for each service discovery, then create a Route to allow external clients to access the application hosted within the virtual machines.

If you have not completed the module Migrating Existing Virtual Machines, it is recommended that you do that module first. If you have not completed it, or the migration process is still pending, you can use pre-existing virtual machines that have been prepared for you, which are available in the vmimported project. If you are using these pre-imported virtual machines, please replace all instances of the vmexamples namespace with vmimported in the examples below.

Introduction to Services

The Service identifies the source/target for traffic, and directs clients to, the endpoints based on labels. Currently, the VMs do not have a label assigned yet.

In order to successfully associate the VMs with the Service, we need to do the following:

  • Add a label to the VMs. We will use the same label for both Windows IIS servers because they are both behind the same load balancer.

  • Create the service to make the two Windows IIS servers available for other workloads on the cluster. OpenShift will automatically make the load balancer internally accessible using the name of the Service as the DNS name.

  • Make the service available outside of OpenShift by creating a Route.

To begin, we’ll add labels to the virtual machines by modifying their definition in the OpenShift Virtualization GUI.

Label the Virtual Machines

  1. From the OpenShift console, navigate to VirtualizationVirtualMachines and ensure the migrated VMs successfully imported and are running.

    11 Imported VMs List
    Ensure you select the correct project, vmexamples-{user} if you completed the Migrating Existing Virtual Machines module or vmimported-{user} if you did not.
  2. Select to the winweb01 VM and navigate to the YAML tab.

  3. Find the spec: section and under the template.metadata add the following lines to labels section in the VM resources:

    env: webapp
    Make sure to get the indentation exactly right - just like in the screenshot below.
    12 Imported VMs YAML
  4. Repeat the process for the VM winweb02.

  5. Start the database virtual machine if it’s not already running.

  6. Start, or restart if already running, the winweb01 and winweb02 virtual machines.

    Ensure the VMs are properly working by accessing to the console tab of each VM.

Create the Service

  1. Navigate to NetworkingServices and press Create Service.

    13 Navigate Service
  2. Replace the YAML with the following definition

    apiVersion: v1
    kind: Service
    metadata:
      name: webapp
      namespace: vmexamples-{user}
    spec:
      selector:
        env: webapp
      ports:
      - protocol: TCP
        port: 80
        targetPort: 80
    Ensure the namespace with your virtual machines, vmexamples-{user} or vmimported-{user}, is the one used in the Service YAML.
    14 Service YAML
  3. Press Create.

  4. From the details page for the newly created webapp Service, locate Pod selector link and click it.

    15 Imported VMs PodSelector
  5. Verify the two Windows VMs are properly identified and targeted by the Service.

    16 Imported VMs Pods

Create the Route

Now the Windows IIS servers are accessible from within the OpenShift cluster. Other virtual machines are able to access them using the DNS name webapp.vmexamples, which is determined by the name of the Service + the namespace. However, since these web servers are the front end to an application we want to be externally accessible, we will expose it using a Route.

  1. Navigate to NetworkingRoutes in the left navigation menu, verify that you’re using the correct project name. Press Create Route.

    17 Route Navigation
  2. Fill the form using the information below, press Create when done.

    1. Name: route-webapp

    2. Service: webapp

    3. Target port: 80 → 80 (TCP)

    4. Secure Route: Enabled

    5. TLS termination: Edge

    6. Insecure traffic: Redirect

      18 Create Route
  3. Navigate to the address shown in Location field

    19 Route Access
  4. When the page loads, you will see an error. This is because the Windows web servers are not able to currently connect to the database VM after it’s migration.

    20 WebApp Error
    To fix the connectivity issue, we need to create a Service for the database VM so that it can be accessed by the web servers.
  5. Once again, navigate to NetworkingServices and press Create Service. Replace the YAML with the following definition:

    apiVersion: v1
    kind: Service
    metadata:
      name: database
      namespace: vmexamples-{user}
    spec:
      selector:
        vm.kubevirt.io/name: {DATABASE_VM_NAME}
      ports:
      - protocol: TCP
        port: 3306
        targetPort: 3306
    This time we used the name of the virtual machine to attach it to the service we are creating, make sure that you update the YAML when you copy/paste it to ensure that you are using the correct name for the database instance in your lab environment.
    21 Database YAML
  6. When the YAML is pasted, click the Create button.

    Ensure the namespace with your virtual machines, vmexamples-{user} or vmimported-{user} is the one used in the Service YAML.
  7. Reload the webapp URL and expect to get the proper result

    22 WebApp Success

Summary

In this module you were able to experience working with the virtual machines that you migrated into the OpenShift Virtualization environment from VMware vSphere by making them accessible outside of the cluster in different manners.

I hope you have enjoyed the OpenShift Virtualization Roadshow and this lab that accompanied it. Please fill out the survey link that your proctor has made available to provide feedback on your experience.