If your Kubernetes project requires a load balancer, you can create a Kubernetes Service of type 'LoadBalancer'. This will automatically create a load balancer (based on our HA-IP Pro platform) by the TransIP Kubernetes platform. Your Kubernetes Control Plane also uses HA-IP Pro.
In this tutorial, we'll show you how to create a LoadBalancer service using Kubectl and what arguments you can pass to it.
Creating a LoadBalancer Service
When you host a Kubernetes Deployment, you can expose it via HA-IP by creating a Service of type LoadBalancer. In the example below, replace 'deploymentname' with the name of your deployment (for example, 'webserver') and 'portnr' with the port number used by that service (for example, 80).
kubectl expose deploy deploymentname --port=portnr --type=LoadBalancer
You will receive a confirmation message that looks like this:
service/deploymentname exposed
You can also see the LoadBalancer when you check the status of your service with the command:
kubectl get service/deploymentname
Your output will look something like this:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
webserver LoadBalancer 10.101.123.45 89-41-123-123.haip.transip.net 80:30058/TCP 13s
It may take a minute or two for the Cloud Control Manager to create the LoadBalancer. Until then, the external IP address will not be visible.
LoadBalancer arguments
When you expose a service, it works automatically, but you can further customize the behavior of your load balancer by setting annotations for your service. The following options are available:
- The available annotations are the same as those available for HA-IP Pro.
- LoadBalancer arguments can be passed when creating Kubernetes objects, see our tutorial on creating Kubernetes objects.
- service.beta.kubernetes.io/transip-loadbalancer-ptr: Sets a Reverse DNS or PTR record for your HA-IP. If not set, a default value is used.
- service.beta.kubernetes.io/transip-loadbalancer-ipsetup: Controls how different IP protocol families are forwarded. Currently, the only options are ipv6to4 (default) and noipv6 for forwarding IPv6 traffic to an IPv4 address, or disabling IPv4 support. Dual-stack clusters are currently not supported.
- service.beta.kubernetes.io/transip-loadbalancer-protocol: Controls the protocol used by HA-IP (default tcp). Available options are tcp, http, proxy, https, and http2.
- service.beta.kubernetes.io/transip-loadbalancer-mode: Sets the load balancing method of the underlying HA-IP (default roundrobin). Available options are roundrobin, source, and cookie.
- service.beta.kubernetes.io/transip-loadbalancer-tls-mode: Determines the minimum supported TLS version (default tls12).
- service.beta.kubernetes.io/transip-loadbalancer-cookie: When using the load balancing method 'cookie', this determines the name of the cookie.
- service.beta.kubernetes.io/transip-loadbalancer-ssl-mode: When using HTTP protocol modes, this option determines whether traffic to the nodes in the K8s cluster uses SSL or not (default off). Available options are off, on (checks SSL but without certificate verification), and strict (SSL verification with certificate verification).
- service.beta.kubernetes.io/transip-loadbalancer-healthcheck-interval: Determines the interval for the health checks performed via TCP or HTTP. The default and minimum value is 2.
- service.beta.kubernetes.io/transip-loadbalancer-healthcheck-path: Sets an address used for health checks when using HTTP mode. The default value is / and the set option must always start with a /.
- service.beta.kubernetes.io/transip-loadbalancer-healthcheck-port: Overrides the port on which health checks are performed. Specifying a configured port on the service automatically translates to the corresponding port on the node in the cluster (see also the output under 'PORT(S)' in the previous paragraph. When this option is not configured, the first (or only) port of the relevant service is used. This option is only relevant for the HTTP mode.
- service.beta.kubernetes.io/transip-loadbalancer-ignore: Marks this service to be ignored by the Cloud Controller Manager (default false). This is especially useful when migrating from one type of controller to another. Values can be: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, and False.