How to use the default load balancer¶
Canonical Kubernetes includes a default load balancer. As this is not an
essential service for all deployments, it is not enabled by default. This guide
explains how to configure and enable the load-balancer.
Prerequisites¶
This guide assumes the following:
You have root or sudo access to the machine.
You have a bootstrapped Canonical Kubernetes cluster (see the Getting Started guide).
Check the status and configuration¶
Find out whether load balancer is enabled or disabled with the following command:
sudo k8s status
The load balancer is not enabled by default.
To check the current configuration of the load-balancer, run the following:
sudo k8s get load-balancer
This should output a list of values like this:
enabled: if set to true, load-balancer is enabledcidrs- a list containing CIDR or IP address ranges for the load balancer’s address pooll2-mode- whether L2 mode (failover) is turned onl2-interfaces- optional list of interfaces to announce services over (defaults to all)bgp-mode- whether BGP mode is active.bgp-local-asn- the local Autonomous System Number (ASN)bgp-peer-address- the peer addressbgp-peer-asn- ASN of the peer networkbgp-peer-port- port used on the BGP peer
These values are configured using the k8s set command, e.g.:
sudo k8s set load-balancer.l2-mode=true
For single-peer BGP using typed keys, set these values in one command:
bgp-mode, bgp-local-asn, bgp-peer-address, and bgp-peer-asn.
bgp-peer-port is optional (default: 179). E.g.
sudo k8s set load-balancer.bgp-mode=true load-balancer.bgp-local-asn=64512 load-balancer.bgp-peer-address=10.0.10.63 load-balancer.bgp-peer-asn=64512 load-balancer.bgp-peer-port=7012
For multi-peer BGP and advertise-all-pools, see How to configure
multi-peer BGP.
Enable the load balancer¶
To enable the load balancer, run:
sudo k8s enable load-balancer
You can now confirm it is working by running:
sudo k8s status
Important
If you run k8s status soon after enabling the load balancer in BGP mode,
k8s status might report errors. Please wait a few moments for the load balancer to finish deploying and try again.
Disable the load balancer¶
The default load balancer can be disabled again with:
sudo k8s disable load-balancer
Next Step¶
Learn more in the Load-balancer explanation page.
For annotation-based multi-peer BGP, see How to configure multi-peer BGP.