Create an External Load Balancer [page]deterministic
This page shows how to create an external load balancer.
When creating a [Service](#gloss:service), you have the option of automatically creating a cloud load balancer. This provides an externally-accessible IP address that sends traffic to the correct port on your cluster nodes, _provided your cluster runs in a supported environment and is configured with the correct cloud load balancer provider package_.
You can also use an [ingress](#gloss:ingress) in place of Service. For more information, check the [Ingress](/docs/concepts/services-networking/ingress/) documentation.
##
Your cluster must be running in a cloud or other environment that already has support for configuring external load balancers.
## Create a Service
### Create a Service from a manifest
To create an external load balancer, add the following line to your Service manifest:
```yaml type: LoadBalancer ```
Your manifest might then look like:
```yaml apiVersion: v1 kind: Service metadata: name: example-service spec: selector: app: example ports: - port: 8765 targetPort: 9376 type: LoadBalancer ```
### Create a Service using kubectl
You can alternatively create the service with the `kubectl expose` command and its `--type=LoadBalancer` flag:
```bash kubectl expose deployment example --port=8765 --target-port=9376 \ --name=example-service --type=LoadBalancer ```
This command creates a new Service using the same selectors as the referenced resource (in the case of the example above, a [Deployment](#gloss:deployment) named `example`).
For more information, including optional flags, refer to the [`kubectl expose` reference](/docs/reference/generated/kubectl/kubectl-commands/#expose).
## Finding your IP address
You can find the IP address created for your service by getting the service information through `kubectl`:
```bash kubectl describe services example-service ```
which should produce output similar to:
``` Name: example-service Namespace: default Labels: app=example Annotations: <none> Selector: app=example Type: LoadBalancer IP Families: <none> IP: 10.3.22.96 IPs: 10.3.22.96 LoadBalancer Ingress: 192.0.2.89 Port: <unset> 8765/TCP TargetPort: 9376/TCP NodePort: <unset> 30593/TCP Endpoints: 172.17.0.3:9376 Session Affinity: None External Traffic Policy: Cluster Events: <none> ```
The load balancer's IP address is listed next to `LoadBalancer Ingress`.
> Note: If you are running your service on Minikube, you can find the assigned IP address and port with:
```bash minikube service example-service --url ```
## Preserving the client source IP
By default, the source IP seen in the target container is *not the original source IP* of the client. To enable preservation of the client IP, the following fields can be configured in the `.spec` of the Service:
* `.spec.externalTrafficPolicy` - denotes if this Service desires to route external traffic to node-local or cluster-wide endpoints. There are two available options: `Cluster` (default) and `Local`. `Cluster` obscures the client source IP and may cause a second hop to another node, but should have good overall load-spreading. `Local` preserves the client source IP and avoids a second hop for LoadBalancer and NodePort type Services, but risks potentially imbalanced traffic spreading. * `.spec.healthCheckNodePort` - specifies the health check node port (numeric port number) for the service. If you don't specify `healthCheckNodePort`, the service controller allocates a port from your cluster's NodePort range. You can configure that range by setting an API server command line option, `--service-node-port-range`. The Service will use the user-specified `healthCheckNodePort` va …(trimmed)