Configuring Load Balancers with Annotations in Kubernetes

Load Balancer - Kubernetes
DateDec 11, 2024

Review your configurations and click Create Load Balancer.

Annotations in Kubernetes provide a way to attach custom metadata to objects, allowing users to configure specific behaviors or features beyond standard options. This flexibility is particularly useful for fine-tuning Load Balancer services in your Kubernetes clusters. To explore annotations further, you can refer to the official Kubernetes documentation.

Annotations can be applied via the Kubernetes command-line tool (kubectl) or defined in the service manifest by including them under the metadata.annotations section. Here’s an example of the structure:

metadata:
 annotations:
  key: "value"

For Gcore-powered clusters, specific annotations are available to enhance Load Balancer functionality. Below is a summary of these annotations:

Key (Annotation)Example ValueTypeDescription
loadbalancer.gcorelabs.com/ddos-profile{"profile_template":65, "fields": [{ "base_field":272, "field_value":40 }]}IntegerApplies a DDoS Protection profile to the Load Balancer.
loadbalancer.gcorelabs.com/flavorlb1-1-2StringSets a custom flavor name for the Load Balancer.
loadbalancer.gcorelabs.com/floating-cleanuptrueBooleanAutomatically removes floating IPs when the Load Balancer is deleted.
loadbalancer.gcorelabs.com/logging-topic-nametopic-123StringSpecifies a LaaS topic for logging (must be used with logging-destination-region-id).
loadbalancer.gcorelabs.com/logging-destination-region-id1IntegerDefines the LaaS destination region for logs (must be paired with logging-topic-name).
loadbalancer.gcorelabs.com/logging-retention-policy-period45IntegerSets the log retention period in days.
loadbalancer.gcorelabs.com/proxy-protocoltrueBooleanEnables proxy protocol for Load Balancer listeners.
loadbalancer.gcorelabs.com/timeout-client-data6000IntegerConfigures client data timeouts (in milliseconds).
loadbalancer.gcorelabs.com/timeout-member-connect6000IntegerSets member connection timeouts (in milliseconds).
loadbalancer.gcorelabs.com/timeout-member-data6000IntegerDefines member data timeouts (in milliseconds).
loadbalancer.gcorelabs.com/x-forwarded-fortrueBooleanAdds headers such as X-Forwarded-For to incoming requests.
service.beta.kubernetes.io/gcore-internal-load-balancertrueBooleanMakes the Load Balancer internal by disabling floating IP creation.
service.beta.kubernetes.io/gcore-external-load-balancertrueBooleanConfigures the Load Balancer to be publicly accessible.

Practical Examples

Below are examples of how to use these annotations in Kubernetes service manifests.

Applying DDoS Protection

To enable an advanced DDoS protection profile for your Load Balancer, include the following in your service manifest:

apiVersion: v1
kind: Service
metadata:
 annotations:
 loadbalancer.gcorelabs.com/ddos-profile: |
{ "profile_template":65, "fields":[{"base_field":272, "field_value":40}] }
 labels:
  app: grafana
 name: grafana
 namespace: default
spec:
 ports:
 port: 80
 protocol: TCP
 targetPort: 80
 selector:
 app: grafana
 type: LoadBalancer

Replace 65, 272, and 40 with the appropriate values for your project. These values should align with the configuration supported by the public DDoS Protection API.

Enabling Logging

To configure logging for your cluster, you can use the following example:

apiVersion: v1
kind: Service
metadata:
 annotations:
  loadbalancer.gcorelabs.com/logging-topic-name: test123
  loadbalancer.gcorelabs.com/logging-destination-region-id: 15
 labels:
  app: grafana
 name: grafana
 namespace: default
spec:
 ports:
  port: 80
  protocol: TCP
  targetPort: 80
 selector:
  app: grafana
 type: LoadBalancer

Make sure to replace test123 and 15 with the appropriate topic name and destination region for your logging configuration.

By customizing your annotations, you can enhance the performance, security, and usability of Load Balancers within your Kubernetes clusters.

© 2024 All Rights Reserved. HostingB2B