Service Discovery and Client Load Balancing

Pivotal/Tanzu Labs

In this lab you will enable your applications to use service discovery to register and locate microservices. The applications will be using Internal Routes on Tanzu Application Service.

At the end of the lab, each application will be able to discover microservices by name, reducing the configuration needed to deploy our system.

Learning outcomes

After completing the lab, you will be able to:

  • Describe the pros and cons of using Service Discovery
  • Describe the pros and cons of using Client Side Load Balancing
  • Explain how to add Client Side Load Balancing and Service Discovery to an application
  • Identify the differences between routing through the Gorouter and container to container networking

Get started

  1. Check out the Concepts slides.

  2. You must have completed (or fast-forwarded to) the Deploy a Distributed Application lab. You must have your pal-tracker application associated with the deploy-distributed-app-solution codebase deployed and running on Tanzu Application Service.

  3. In a terminal window, make sure you start in the ~/workspace/pal-tracker directory.

You will make no code changes in the lab. You will make only configuration changes to your distributed app running on Tanzu Application Service.

Configure Internal Routes

  1. Make sure your work is saved and committed to Github.

  2. Configure network policies for your consuming applications tracker-allocations, tracker-backlog, tracker-timesheets to talk to tracker-registration:

    cf add-network-policy tracker-allocations --destination-app tracker-registration
    cf add-network-policy tracker-backlog --destination-app tracker-registration
    cf add-network-policy tracker-timesheets --destination-app tracker-registration
    
  3. Find out the internal route domain for your foundation:

    cf domains
    

    look for the domain of the entry marked “Internal”.

  4. Create an internal route for the tracker-registration application using the unique identifier for the host name you used in this lab, as well as the internal domain you found in the previous step:

    cf map-route tracker-registration ${INTERNAL_DOMAIN} --hostname=registration-pal-${UNIQUE_IDENTIFIER}
    
  5. Set the registration server endpoint configuration to point to the internal route:

    cf set-env tracker-allocations REGISTRATION_SERVER_ENDPOINT http://registration-pal-${UNIQUE_IDENTIFIER}.${INTERNAL_DOMAIN}:8080
    cf set-env tracker-backlog REGISTRATION_SERVER_ENDPOINT http://registration-pal-${UNIQUE_IDENTIFIER}.${INTERNAL_DOMAIN}:8080
    cf set-env tracker-timesheets REGISTRATION_SERVER_ENDPOINT http://registration-pal-${UNIQUE_IDENTIFIER}.${INTERNAL_DOMAIN}:8080
    
  6. Restart the consuming applications to pick up the new route:

    cf restart tracker-allocations
    cf restart tracker-backlog
    cf restart tracker-timesheets
    
  7. Run through the curl commands to verify the container-to-container integration works.

Wrap up

Checkout the Implementation slides about some types of Service Discovery implementations.

Now that you have completed the lab, you will be able to:

  • Describe the pros and cons of using Service Discovery
  • Describe the pros and cons of using Client Side Load Balancing
  • Explain how to add Client Side Load Balancing and Service Discovery to an application
  • Identify the differences between routing through the Gorouter and container to container networking