Creating a Load Balancer for your Kubernetes cluster allows you to expose an application running inside your cluster to the internet.
In this document, we summarize when to create a Load Balancer for your cluster (as opposed to a different solution for exposing your application), and take you through the basic steps to create and configure your Load Balancer.
Does your cluster need a Load Balancer?Before creating a Load Balancer for your cluster, ensure that this is definitely the best solution for what you want to achieve.
A single LoadBalancer Service is sufficient for exposing one service in your cluster. Each further service will need its own external Load Balancer (which should generally be set up to forward TCP traffic) and corresponding LoadBalancer
Service.
However, remember that Load Balancers are a paid-for resource. Consider whether one of the following free solutions might be appropriate if you have a relatively simple cluster:
On the other hand, if you have multiple services running in a more complex cluster, and you want to forward traffic to the right service based on HTTP, consider the following:
Read the full documentation on different ways to expose your services for full details, and links to the relevant documentation for each possibility.
Creating a Load Balancer for your cluster: OverviewHere is a quick overview of how to create a Load Balancer for your cluster:
Load Balancers for Kubernetes clusters should always be provisioned via the cluster's Cloud Controller Manager. It is not correct procedure to provision the Load Balancer by creating a Scaleway Load Balancer in the console or via the API, and then attempting to use it as your cluster's external Load Balancer. Similarly, you cannot use the Scaleway console or developer tools to edit your cluster's Load Balancer after creation, this must be done via the CCM, as detailed in this documentation.
Creating a Load Balancer for your cluster: Step by step Before you startTo complete the actions presented below, you must have:
You can refer to the following example of webserver application to run.
Create a .yaml
file to hold the manifest for your cluster's Load Balancer. This will describe the resource (Load Balancer) that you want to create.
Below, find an example for the content of the yaml manifest. You will need to edit it to your own specifications.
apiVersion: v1
kind: Service
metadata:
name: myloadbalancer
spec:
type: LoadBalancer
ports:
- port: 8000
name: http
targetPort: 8000
selector:
app: mydeployment
apiVersion
: which version of the Kubernetes API to use to create the objectkind
: the kind of object defined in this YAML file. For a Load Balancer, specify a Service
metadata
: helps uniquely identify the Service object: give it a name
(e.g. myloadbalancer
).spec
: specifies the Service:
type
: the type of Service required: a LoadBalancer
Service.ports
: the ports for the Service configuration. You can define many ports if you want, here we specify just one:port
: the new service port that will be created, for connecting to the applicationname
: a name for this port, e.g. http
targetPort
: the application port to target with requests coming from the Serviceselector
: links the LoadBalancer Service with a set of pods in the cluster. Ensure that the app
specified matches the name of the deployment of your app in the cluster (run kubectl get all
if necessary to check the name).Use the command kubectl create -f <name-of-manifest-file>.yaml
to tell the Kubernetes Cloud Controller to create the Load Balancer from the manifest in the default namespace.
Run kubectl get svc
to confirm that the Load Balancer Service has been created, and view its external IP. You can also check the Load Balancer section of the Scaleway console, where your Kuberenetes cluster's Load Balancer now appears. Note that you should not attempt to edit or delete the Load Balancer via the console, only via the manifest file and kubectl.
By default, when you create a Load Balancer for your cluster, it will be assigned a public IP address at random. When you delete the Load Balancer, the IP address will also be deleted, and cannot be retrieved to transfer to another Load Balancer service in your cluster.
However, it is possible to use flexible IP addresses with your cluster's Load Balancer, to give you more control over the IPs being used. Flexible IP addresses can be kept in your account even if/when their associated Load Balancer is deleted. They can then be assigned to a new Load Balancer in the future.
To specify that an existing flexible IP address that you hold in your account should be used when creating your Load Balancer, add the loadBalancerIP
field to your yaml manifest, as shown in the last line here:
apiVersion: v1
kind: Service
metadata:
name: myloadbalancer
spec:
type: LoadBalancer
ports:
- port: 8000
name: http
targetPort: 8000
selector:
app: mydeployment
loadBalancerIP: 51.159.24.7
For full details and further examples of how to use flexible IPs with your Kubernetes Load Balancer, see our dedicated documentation.
Defining your Load Balancer's configuration via annotationsYour Load Balancer will be created with a default configuration unless you define configuration parameters via annotations.
With annotations, you can configure parameters such as the balancing method, health check settings, and more.
ImportantYou should never try to modify the configuration of your cluster's Load Balancer via the Scaleway console, the API, or any other developer tools. Any modifications made this way will be overwritten by the cluster's CCM. You should always use annotations as described below to configure your cluster's Load Balancer.
Add annotations to the metadata
section of your LoadBalancer Service's yaml manifest as shown below. In this example we include two annotations, but you can include as many as you need.
apiVersion: v1
kind: Service
metadata:
name: myloadbalancer
annotations:
service.beta.kubernetes.io/scw-loadbalancer-forward-port-algorithm: "leastconn"
service.beta.kubernetes.io/scw-loadbalancer-health-check-delay: "10s"
spec:
type: LoadBalancer
ports:
- port: 8000
name: http
targetPort: 8000
selector:
app: mydeployment
For full details on how to use Load Balancer annotations when creating your Load Balancer, or how to modify your Load Balancer's annotations after creation, see our dedicated documentation. For a full list of Load Balancer annotations, refer to the Scaleway Cloud Controller documentation.
Troubleshooting Kubernetes Load Balancers Load Balancer certificate error using SSL offloadIf your Load Balancer is configured for SSL offload, and you have several services behind the same Load Balancer, you will encounter an SSL error when trying to reach the other services using HTTPS.
Example:
https://serviceB.example.com
)From podA, a curl to https://serviceB.example.com
will result in an SSL error.
To force the Load Balancer to handle all requests using the SSL offload, enable the use hostname annotations on your Load Balancer service.
Load Balancer TCP Proxy and Nginx Ingress error 400If your Load Balancer is configured using TCP Proxy and you are using an Nginx Ingress, you might encounter an HTTP 400 error.
The Nginx Ingress must be configured with use-proxy-protocol to accept TCP Proxy requests.
Nginx Ingress Easy DeployThe Easy Deploy Nginx Ingress can be configured to accept TCP Proxy:
controller:
service:
annotations:
service.beta.kubernetes.io/scw-loadbalancer-proxy-protocol-v2: "true"
service.beta.kubernetes.io/scw-loadbalancer-use-hostname: "true"
config:
use-forwarded-headers: true
compute-full-forwarded-for: true
use-proxy-protocol: true
Further resources
For more help and support using Scaleway Load Balancers with your Kubernetes cluster, check out the following resources:
* Though this documentation may be useful, bear in mind that it principally concerns Load Balancers outside a Kubernetes context. Remember to always create and configure Load Balancers for your Kubernetes cluster via the methods described on this page and not via the Scaleway console, API, or developer tools.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4