Git Product home page Git Product logo

cloud-services-dotnet-internal-load-balancer's Introduction

services platforms author
cloud-services
dotnet
msonecode

How to create Internal Load Balancer for PaaS cloud service

Introduction

Sometimes, we only want to allow cloud service be accessed within a virtual network, or we want to access cloud service by static IP within a virtual network. This example helps you to configure Internal Load Balancer for web role. This ILB can also be used as worker. In this sample, we will be binding an ILB with port 8080 for web role. Note: If you bind a port for ILB, this port will only be accessible by ILB.

Prerequisites

Virtual Network

Internal Load Balance needs you to deploy a virtual network. Please follow the below wizard to create one. https://azure.microsoft.com/en-us/documentation/articles/virtual-networks-create-vnet-classic-portal/

Building the Sample

1. Open Solution in Visual Studio 2015

Now you can use Visual Studio 2015 to build a cloud service solution. This solution contains cloud service project with 1 web role project and 1 work role.

2. Configure Service Definition File

Open ServiceDefinition.csdef, add a Endpoint2 for load balancer to use. Change the following settings as yours.

  <WebRole name="WebRole1" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
          <Binding name="Endpoint2" endpointName="Endpoint2" />
        </Bindings>
      </Site>
    </Sites>
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
    </ConfigurationSettings>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
      <InputEndpoint name="Endpoint2" protocol="http" port="8080" loadBalancer="name of the load balancer" />
    </Endpoints>
    <Imports>
      <Import moduleName="RemoteAccess" />
    </Imports>
  </WebRole>

This cloud service has 2 endpoints. Once we have binded the endpoint2 with ILB, it will no longer be accessible by cloudservice.cloudapp.net:endpoint2. This endpoint2 can then be accessed only by ILB’s IP + port. If we don’t want cloud service to be accessible from outside the VNet, just remove the endpoint1.

3. Configure Service Configuration File

Open ServiceConfiguration.Cloud.cscfg and change content as below. Change the following settings as yours.

<NetworkConfiguration>
    <VirtualNetworkSite name="name of virtual network" />
    <AddressAssignments>
      <InstanceAddress roleName="WebRole1">
        <Subnets>
          <Subnet name="Subnet-1" />
        </Subnets>
      </InstanceAddress>
      <InstanceAddress roleName="WorkerRole1">
        <Subnets>
          <Subnet name="Subnet-1" />
        </Subnets>
      </InstanceAddress>
    </AddressAssignments>
    <LoadBalancers>
      <LoadBalancer name="name of the load balancer">
        <FrontendIPConfiguration type="private" subnet="Subnet-1" staticVirtualNetworkIPAddress="static-IP-address" />
      </LoadBalancer>
    </LoadBalancers>
  </NetworkConfiguration>

Add the above configuration under last </ Role>.

Running the Sample

  • Right click cloud service project and choose “Publish…” command.

1

  • Choose an existed or create a new Cloud Service in cloud service dropdown list.

2

  • Choose an existed or create a new Storage Account in storage account dropdown list.

3

  • Then publish this cloud service.

4

How to verify

We can log on to a VM within that Azure Virtual Network, then try accessing the Cloud Service by ILB's IP with port 8080 to verify if the internal load balancer works fine or not.

cloud-services-dotnet-internal-load-balancer's People

Contributors

acomsmpbot avatar aliceqin12 avatar vaanpan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.