Kahibaro
Discord Login Register

Load balancing

Types of Load Balancing in OpenShift

OpenShift builds on Kubernetes primitives to provide several layers of load balancing. Each layer solves a different problem: distributing traffic between nodes, between pods, and sometimes across clusters or external systems. Understanding which layer to use in which situation is key to designing reliable applications.

At a high level, you’ll encounter:

This chapter focuses on what is specific to load balancing in OpenShift, not on the basic definitions of Services, Routes, or Ingress.


Cluster-Internal Load Balancing (Service-Level)

Within the cluster, OpenShift uses Kubernetes Service objects to distribute traffic to pods that match a label selector. The most common types and their load-balancing behavior:

ClusterIP Services

ClusterIP is the default Service type and provides:

When clients inside the cluster send traffic to the Service IP:

Use ClusterIP when:

Example (simplified):

apiVersion: v1
kind: Service
metadata:
  name: my-app
spec:
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 8080

This Service will load-balance connections to all my-app pods exposing port 8080.

Session Affinity (Client IP Stickiness)

Some applications require that all requests from a client go to the same pod (session stickiness). OpenShift/Kubernetes services can provide session affinity based on client IP.

Key points:

Example:

apiVersion: v1
kind: Service
metadata:
  name: cart-service
spec:
  selector:
    app: web-shop
  ports:
    - port: 80
      targetPort: 8080
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 10800   # 3 hours

Trade-offs:

Use this when application-level session handling (e.g., sticky cookies, stateless design) is not available or would be too complex to add.


Node-Level Load Balancing (NodePort and External Load Balancers)

For traffic entering the cluster from outside, OpenShift clusters usually sit behind external load balancers or cloud provider load-balancer services. The low-level Kubernetes concepts still apply, but OpenShift often abstracts or automates parts of the setup.

NodePort Behavior

A NodePort Service:

This is mainly used when:

Example:

apiVersion: v1
kind: Service
metadata:
  name: nodeport-web
spec:
  type: NodePort
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 30080

Considerations:

External Load Balancers

In cloud or virtualized environments, OpenShift clusters often use infrastructure load balancers:

Typical pattern:

  1. External load balancer distributes traffic across worker node IPs (or across dedicated ingress nodes).
  2. On each node, kube-proxy forwards incoming traffic to the appropriate Service.
  3. That Service then load-balances to its pods.

Important aspects:

OpenShift clusters installed with Installer-Provisioned Infrastructure (IPI) often set up these external load balancers automatically, especially for the API and Ingress endpoints.


Application Ingress and HTTP(S) Load Balancing

At the HTTP(S) layer, OpenShift uses Ingress Controllers (usually HAProxy-based) to provide routing and load balancing for web applications that use Routes or Ingress resources.

Ingress Controller Role

The OpenShift Ingress Controller:

While Services handle L3/L4 distribution, Ingress Controllers add L7 (HTTP/HTTPS) awareness:

Load Balancing via Routes

OpenShift Routes are the primary way to expose HTTP/S applications. Each Route references a Service, and the Ingress Controller load-balances traffic from clients to that Service’s pods.

Key behaviors:

Example Route with simple round-robin:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: my-app
spec:
  host: my-app.apps.example.com
  to:
    kind: Service
    name: my-app
    weight: 100
  port:
    targetPort: 8080
  tls:
    termination: edge

In this case:

Sticky Sessions with Routes (Cookie-Based Affinity)

For web sessions, you often want stickiness at HTTP level, not IP level. OpenShift Routes support cookie-based session affinity.

You configure this using annotations or route-specific options (version-dependent). Typical concept:

Behavior and drawbacks:

Load Balancing for Different Protocols

While HTTP(S) dominates most workloads, OpenShift supports load balancing for various protocols.

HTTP, HTTPS, and WebSockets

For gRPC:

TCP and UDP Load Balancing

For raw TCP or UDP protocols:

Scenarios:

Considerations:

Load Balancer Health Checks and Failure Handling

Effective load balancing depends on accurate detection of failing nodes or pods.

Node and Pod Health in Load Balancing

On the pod level:

On the node level:

This layering helps avoid sending traffic:

Graceful Draining and Rolling Updates

During rolling updates or node maintenance:

Implications:

Properly configured draining is critical to achieve zero-downtime deployments and minimize user-visible errors.


Load Balancing in Multi-Zone and Hybrid Setups

OpenShift clusters can span multiple availability zones or be part of hybrid (on-prem + cloud) environments. Load balancing has additional considerations here.

Zone-Aware Load Balancing

External load balancers and Ingress Controllers can be configured to:

Depending on your infrastructure:

Global and Cross-Cluster Load Balancing (High-Level)

For multi-cluster or hybrid strategies (e.g., DR, blue/green across clusters):

Within each cluster, the mechanisms described above still apply; the new complexity is how traffic is split between clusters.


Performance and Tuning Considerations

While exact tuning depends on environment and scale, a few general principles are specific to load balancing on OpenShift:

Tuning these parameters is usually part of capacity planning and operations, but understanding their impact on load balancing behavior helps you design applications that behave well under varying load.


Designing Applications for OpenShift Load Balancing

To make best use of OpenShift’s load-balancing features:

By combining these design practices with OpenShift’s layering of load-balancing mechanisms, you can build applications that are resilient, scalable, and efficient in real-world traffic conditions.

Views: 15

Comments

Please login to add a comment.

Don't have an account? Register now!