diff --git a/slides/kube/kubectlexpose.md b/slides/kube/kubectlexpose.md index 1010ca18..391e2144 100644 --- a/slides/kube/kubectlexpose.md +++ b/slides/kube/kubectlexpose.md @@ -138,3 +138,87 @@ Note: please DO NOT call the service `search`. It would collide with the TLD. -- Our requests are load balanced across multiple pods. + +--- + +class: extra-details + +## If we don't need a load balancer + +- Sometimes, we want to access our scaled services directly: + + - if we want to save a tiny little bit of latency (typically less than 1ms) + + - if we need to connect over arbitrary ports (instead of a few fixed ones) + + - if we need to communicate over another protocol than UDP or TCP + + - if we want to decide how to balance the requests client-side + + - ... + +- In that case, we can use a "headless service" + +--- + +class: extra-details + +## Headless services + +- A headless service is obtained by setting the `clusterIP` field to `None` + + (Either with `--cluster-ip=None`, or by providing a custom YAML) + +- As a result, the service doesn't have a virtual IP address + +- Since there is no virtual IP address, there is no load balancer either + +- `kube-dns` will return the pods' IP addresses as multiple `A` records + +- This gives us an easy way to discover all the replicas for a deployment + +--- + +class: extra-details + +## Services and endpoints + +- A service has a number of "endpoints" + +- Each endpoint is a host + port where the service is available + +- The endpoints are maintained and updated automatically by Kubernetes + +.exercise[ + +- Check the endpoints that Kubernetes has associated with our `elastic` service: + ```bash + kubectl describe service elastic + ``` + +] + +In the output, there will be a line starting with `Endpoints:`. + +That line will list a bunch of addresses in `host:port` format. + +--- + +class: extra-details + +## Viewing endpoint details + +- When we have many endpoints, the previous command truncates the list + +- If we want to see the full list, we can use one of the following commands: + ```bash + kubectl describe endpoint elastic + kubectl get endpoint elastic -o yaml + ``` + +- These addresses will show us a list of IP addresses + +- These IP addresses should match the addresses of the corresponding pods: + ```bash + kubectl get pods -l run=elastic -o wide + ```