Kubernetes - Les endpoints

Le endpoint est “l’interface” entre le service et les pods associés.
C’est une collection d’IP et ports exposé par les pods.
Quand un service est créé, Kubernetes crée automatiquement et associe un endpoint.
L’objet endpoint maintient les IP et port des pods (ajout/suppression/changement) qui matche le selector du service.
Kubernetes endpoint

Afficher les endpoints

k get endpoints
NAME         ENDPOINTS                     AGE
hello        10.244.0.2:80,10.244.1.2:80   20d
k describe endpoints hello
Name:         hello
Namespace:    default
Labels:       <none>
Annotations:  endpoints.kubernetes.io/last-change-trigger-time: 2024-09-09T18:12:43Z
Subsets:
  Addresses:          10.244.0.2,10.244.1.2
  NotReadyAddresses:  <none>
  Ports:
    Name     Port  Protocol
    ----     ----  --------
    <unset>  80    TCP

Events:  <none>
k get endpoints hello -o yaml
apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    endpoints.kubernetes.io/last-change-trigger-time: "2024-09-09T18:12:43Z"
  creationTimestamp: "2024-08-20T15:47:51Z"
  name: hello
  namespace: default
  resourceVersion: "154998"
  uid: d614cd15-2494-4204-95fe-74ea5af1c8bf
subsets:
- addresses:
  - ip: 10.244.0.2
    nodeName: minikube
    targetRef:
      kind: Pod
      name: hello-7865c89f4d-qwgwj
      namespace: default
      uid: 04ab4041-de8e-4973-b16a-2fd84cc72f5a
  - ip: 10.244.1.2
    nodeName: minikube-m02
    targetRef:
      kind: Pod
      name: hello-7865c89f4d-4sxlm
      namespace: default
      uid: 4716ec44-351e-4bed-a35b-44617d6370f5
  ports:
  - port: 80
    protocol: TCP

Note: une ressource endpoint a une limitation à 1000 backend endpoints (pods), pour répondre à ce problème Kubernetes à ajouté le endpointSlice depuis la v1.21.
Cela génére aussi des volumes dans la base ETCD.

Les endpointSlices

Kubernetes endpointslice Les endpointSlices permettent d’aller au dela des 1000 endpoints backend (pods) par endpoint, par défaut il y a 100 pods par endpointslice, c’est possible de le modifier via le flag –max-endpoints-per-slice à la configuration du kube-controller-manager.

k get endpointslices 
NAME          ADDRESSTYPE   PORTS   ENDPOINTS               AGE
hello-lqqm2   IPv4          80      10.244.0.2,10.244.1.2   20d
k get endpointslices hello-lqqm2 -o yaml
addressType: IPv4
apiVersion: discovery.k8s.io/v1
endpoints:
- addresses:
  - 10.244.0.2
  conditions:
    ready: true
    serving: true
    terminating: false
  nodeName: minikube
  targetRef:
    kind: Pod
    name: hello-7865c89f4d-qwgwj
    namespace: default
    uid: 04ab4041-de8e-4973-b16a-2fd84cc72f5a
- addresses:
  - 10.244.1.2
  conditions:
    ready: true
    serving: true
    terminating: false
  nodeName: minikube-m02
  targetRef:
    kind: Pod
    name: hello-7865c89f4d-4sxlm
    namespace: default
    uid: 4716ec44-351e-4bed-a35b-44617d6370f5
kind: EndpointSlice
metadata:
  annotations:
    endpoints.kubernetes.io/last-change-trigger-time: "2024-09-09T18:12:43Z"
  creationTimestamp: "2024-08-20T15:47:51Z"
  generateName: hello-
  generation: 59
  labels:
    endpointslice.kubernetes.io/managed-by: endpointslice-controller.k8s.io
    kubernetes.io/service-name: hello
  name: hello-lqqm2
  namespace: default
  ownerReferences:
  - apiVersion: v1
    blockOwnerDeletion: true
    controller: true
    kind: Service
    name: hello
    uid: cd7da9c9-9d55-4d6a-8dee-29019c40091c
  resourceVersion: "154997"
  uid: 16d512b5-29f5-4e8c-8b56-182b7b01e9ef
ports:
- name: ""
  port: 80
  protocol: TCP
k describe endpointslices hello-lqqm2
Name:         hello-lqqm2
Namespace:    default
Labels:       endpointslice.kubernetes.io/managed-by=endpointslice-controller.k8s.io
              kubernetes.io/service-name=hello
Annotations:  endpoints.kubernetes.io/last-change-trigger-time: 2024-09-09T18:12:43Z
AddressType:  IPv4
Ports:
  Name     Port  Protocol
  ----     ----  --------
  <unset>  80    TCP
Endpoints:
  - Addresses:  10.244.0.2
    Conditions:
      Ready:    true
    Hostname:   <unset>
    TargetRef:  Pod/hello-7865c89f4d-qwgwj
    NodeName:   minikube
    Zone:       <unset>
  - Addresses:  10.244.1.2
    Conditions:
      Ready:    true
    Hostname:   <unset>
    TargetRef:  Pod/hello-7865c89f4d-4sxlm
    NodeName:   minikube-m02
    Zone:       <unset>
Events:         <none>