Creating a Loadbalancer
In the previous section we created a pod running an nginx webserver. Now we need a way to make the webserver accessible from the Internet. In the Nectar Cloud, we can do this by creating a load balancer.
A load balancer has a public (floating) IP. Client accessing via this public IP are redirected to one or more private addresses within the cluster.
(Note that a Magnum cluster is configured with 2 loadbalancers for cluster management. The loadbalancer we will be creating here is for a different purpose.)
Create a yaml file to describe the configuration for your load balancer. Save the following as
apiVersion: v1 kind: Service metadata: name: nginxservice spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: run: webserver type: LoadBalancer
Create the loadbalancer using the yaml file:
$ kubectl apply -f nginxservice.yaml service/nginxservice created
Run the following to see the details of the loadbalancer, and wait until the output shows
$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginxservice LoadBalancer 10.254.210.248 22.214.171.124 80:31086/TCP 5m
Tip: If you use the
-wflag with any
kubectl getcommand, it will watch for changes from the server and print out status updates as they happen.
Verify that the webserver is accessible. From your browser, visit the IP in the
EXTERNAL-IPfield. You should see the default nginx page.
This is what we just did:
We started an external
LoadBalancerservice in Kubernetes, and directed it at the
webserverpod that we created previously.
Kubernetes created the loadbalancer (externally) by calling out to the OpenStack loadbalancer provider plugin.
The plugin sent Openstack requests to create the resources to make it all work, namely: a floating ip address, a security group, and a load balancer, pool listener and members.
We observed what had been set up:
You can see the loadbalancer from the Kubernetes perspective by running
kubectl get services
You can also see the resources from the Openstack perspective using the
openstackcommand line; e.g.
openstack floating ip list,
openstack loadbalancer listand so on.
Finally, we checked that the loadbalancer was working using a web browser.
For more information, refer to: