> ## Documentation Index
> Fetch the complete documentation index at: https://www.latitude.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LoadBalancer Services

> Required fields and supported annotations for LKS LoadBalancer Services

To expose a Workload, create a Kubernetes `Service` of type `LoadBalancer`. This page covers the one required field and the annotations LKS supports. For the model behind it, see [Exposing Workloads](/docs/lks/exposing-workloads).

## Required: the LoadBalancer class

Every LKS LoadBalancer Service must set `spec.loadBalancerClass` to `latitude.sh/elastic-ip`. Without it, the Service never receives an external IP and its `EXTERNAL-IP` stays `<pending>`.

```yaml theme={null}
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: LoadBalancer
  loadBalancerClass: latitude.sh/elastic-ip
  selector:
    app: web
  ports:
    - name: http
      port: 80
      targetPort: 8080
```

Apply it and read back the assigned address:

```bash theme={null}
kubectl get service web
```

A Latitude [Elastic IP](/docs/networking/elastic-ips-bgp) is allocated in the Cluster's region and, once it's announced, populates `EXTERNAL-IP`.

## Preserve the client source IP

To keep the Service highly available and preserve the client source IP, set `externalTrafficPolicy: Local` and run at least two replicas across Nodes. See [High availability](/docs/lks/exposing-workloads#high-availability).

```yaml theme={null}
spec:
  type: LoadBalancer
  loadBalancerClass: latitude.sh/elastic-ip
  externalTrafficPolicy: Local
  # ...
```

## Annotations

LKS supports two annotations for controlling the Elastic IP behind a Service.

| Annotation                            | Value         | Default                              | Effect                                                                                                                   |
| ------------------------------------- | ------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| `lks.latitude.sh/adopt-elastic-ip`    | Elastic IP id | None. A new Elastic IP is allocated. | Reuse an existing Latitude Elastic IP instead of allocating a new one. Keeps a stable address across Service recreation. |
| `lks.latitude.sh/preserve-elastic-ip` | `"true"`      | `"false"`                            | Keep the Elastic IP reserved when the Service is deleted, so you can reuse it later.                                     |

```yaml theme={null}
apiVersion: v1
kind: Service
metadata:
  name: web
  annotations:
    lks.latitude.sh/adopt-elastic-ip: '<elastic-ip-id>'
    lks.latitude.sh/preserve-elastic-ip: 'true'
spec:
  type: LoadBalancer
  loadBalancerClass: latitude.sh/elastic-ip
  # ...
```

### Adopting an Elastic IP

The Elastic IP you adopt must belong to the same project and region as the Cluster and be a BGP-mode address that isn't already in use. If it doesn't qualify, the Service stays pending and the platform records the reason as an event on the Service:

```bash theme={null}
kubectl describe service web
```

### Preserving an Elastic IP

<Note>
  A preserved Elastic IP stays reserved after you delete the Service, and reserved Elastic IPs [continue to bill](https://www.latitude.sh/pricing/networking#ips). Release it when you no longer need the address.
</Note>
