> For the complete documentation index, see [llms.txt](https://a7246c5516ab4c80cdfe21ca2be3e40c.gitbook.io/kubernetes-basics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://a7246c5516ab4c80cdfe21ca2be3e40c.gitbook.io/kubernetes-basics/load-balancing.md).

# load balancing

Load balancing is a technique used to distribute incoming network traffic across multiple servers to ensure no single server is overwhelmed. Here are some common usages of load balancing along with examples:

#### 1. **Distributing Web Traffic:**

* **Usage:**
  * Balancing incoming HTTP/HTTPS requests across multiple web servers.
* **Example:**
  * Using a load balancer to distribute requests to a cluster of web servers hosting a website.

#### 2. **TCP/UDP Load Balancing:**

* **Usage:**
  * Balancing non-HTTP traffic, such as database connections or custom protocols.
* **Example:**
  * A load balancer distributing TCP requests to a set of backend servers running a database.

#### 3. **Layer 4 Load Balancing:**

* **Usage:**
  * Distributing traffic based on information from the transport layer (e.g., IP addresses and ports).
* **Example:**
  * A load balancer forwarding traffic based on IP addresses and TCP/UDP ports.

#### 4. **Layer 7 Load Balancing:**

* **Usage:**
  * Distributing traffic based on information from the application layer (e.g., URL paths or HTTP headers).
* **Example:**
  * A load balancer forwarding requests to different backend servers based on the content of the HTTP request.

#### 5. **Round Robin Load Balancing:**

* **Usage:**
  * Distributing traffic equally among a set of servers in a rotation.
* **Example:**
  * A load balancer sending requests to Server 1, then Server 2, and so on, in a circular fashion.

#### 6. **Weighted Load Balancing:**

* **Usage:**
  * Assigning different weights to servers based on their capacity or performance.
* **Example:**
  * A load balancer directing more traffic to a high-capacity server by assigning it a higher weight.

#### 7. **Session Persistence:**

* **Usage:**
  * Ensuring that a user's requests are consistently directed to the same server for the duration of a session.
* **Example:**
  * Using session cookies or IP-based persistence to maintain user sessions.

#### 8. **Health Checks:**

* **Usage:**
  * Monitoring the health of backend servers and directing traffic away from unhealthy servers.
* **Example:**
  * A load balancer periodically checking the health of servers and excluding unhealthy servers from the rotation.

#### 9. **Global Server Load Balancing (GSLB):**

* **Usage:**
  * Distributing traffic across multiple data centers or geographically dispersed servers.
* **Example:**
  * A load balancer directing users to the nearest server or data center based on their geographical location.

#### 10. **Content-Based Load Balancing:**

```
- **Usage:**
  - Routing traffic based on the type or content of the requested data.
- **Example:**
  - A load balancer directing video streaming requests to servers optimized for video processing.
```

#### 11. **Auto-Scaling Load Balancing:**

```
- **Usage:**
  - Automatically adjusting the number of backend servers based on demand.
- **Example:**
  - An auto-scaling group of servers behind a load balancer that dynamically adjusts based on traffic volume.
```

#### 12. **SSL/TLS Termination Load Balancing:**

```
- **Usage:**
  - Offloading SSL/TLS encryption and decryption from backend servers to the load balancer.
- **Example:**
  - A load balancer handling SSL/TLS termination to reduce the processing load on backend servers.
```

#### 13. **Ingress Load Balancing (for Kubernetes):**

```
- **Usage:**
  - Distributing external traffic to services within a Kubernetes cluster.
- **Example:**
  - A Kubernetes Ingress controller using a load balancer to route external requests to different services based on hostnames or paths.
```

#### 14. **Application Delivery Controllers (ADC):**

```
- **Usage:**
  - Providing advanced load balancing features and application optimization.
- **Example:**
  - Using a dedicated ADC appliance to balance traffic, perform SSL termination, and optimize application performance.
```

#### 15. **CDN Load Balancing:**

```
- **Usage:**
  - Distributing content across a content delivery network (CDN) to reduce latency.
- **Example:**
  - A CDN load balancer directing users to the nearest edge server to deliver cached content quickly.
```

These examples illustrate how load balancing can be applied in various scenarios to improve the performance, reliability, and scalability of applications and services.
