Expose a Service
Give a Kubernetes Service of type LoadBalancer a {{product}} load balancer, with TLS at the balancer for names in your DNS zones.
A Service of type: LoadBalancer gets a Deutsche Cloud load balancer, made and deleted with the
Service. It bills as a load balancer. The balancer sits in the cluster's network and forwards each
Service port to that port's NodePort on the nodes' private addresses. With
externalTrafficPolicy: Local it sends only to nodes that run a ready pod.
Prerequisites
- kubectl access to the cluster:
eks:AccessKubernetesApiin IAM and an access entry whose policy lets you create Services in the namespace (Editor more; see Connect with kubectl). - For HTTPS at the balancer: the names in a hosted zone of your organization in Deutsche Cloud DNS.
Create the Service
apiVersion: v1
kind: Service
metadata:
name: web
annotations:
lb.ews.cloud/https-ports: "443"
lb.ews.cloud/certificate-domains: shop.example.com,www.shop.example.com
lb.ews.cloud/redirect-http: "true"
spec:
type: LoadBalancer
selector: { app: web }
ports:
- { name: https, port: 443, targetPort: 8080 }Apply it with kubectl apply -f web.yaml, then point a DNS record at the EXTERNAL-IP that
kubectl get service web shows.
Annotation (lb.ews.cloud/…) |
Effect |
|---|---|
type |
lb11 (default), lb21 or lb31: the balancer's size |
algorithm |
round_robin (default) or least_connections |
proxy-protocol |
"true": TCP ports prepend PROXY protocol v1 (your server must expect it) |
https-ports |
Ports where the balancer terminates TLS and forwards plain HTTP; needs the next one |
certificate-domains |
Names in your DNS zones for the certificate, which Deutsche Cloud issues and renews |
redirect-http |
"true": port 80 redirects to HTTPS; needs an HTTPS port, and the Service must not use 80 |
health-check-path |
HTTP path checked on HTTPS ports (default /); ignored with externalTrafficPolicy: Local |
With externalTrafficPolicy: Local the balancer checks every port on the Service's health-check
NodePort (/healthz), so only nodes running a ready pod receive traffic. Otherwise TCP ports get a
TCP check on their NodePort. An HTTPS port is added to the balancer once its certificate is issued.
Limits
- TCP only. A Service with a UDP port gets no balancer, and the reason is in the Service's events.
- Every port needs a NodePort (
allocateLoadBalancerNodePortsmust stay on). - The balancers of a cluster are listed on the cluster's Networking tab, with their address and
any error, for someone allowed
lb:DescribeLoadBalancers.
Related
- Install an add-on (Traefik serves many Ingresses behind one balancer)
- Use persistent volumes