Skip to content

Commit

Permalink
feat(NSC): use EndpointSlice instead of Endpoints
Browse files Browse the repository at this point in the history
With the advent of IPv6 integrated into the NSC we no longer get all IPs
from endpoints, but rather just the primary IP of the pod (which is
often, but not always the IPv4 address).

In order to get all possible endpoint addresses for a given service we
need to switch to using EndpointSlice which also nicely groups addresses
into IPv4 and IPv6 by AddressType and also gives us more information
about the endpoint status by giving us attributes for serving and
terminating, instead of just ready or not ready.

This does mean that users will need to add another permission to their
RBAC in order for kube-router to access these objects.
  • Loading branch information
aauren committed Sep 23, 2023
1 parent f8d9812 commit 327e894
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ rules:
- services/status
verbs:
- update
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
Expand Down
8 changes: 8 additions & 0 deletions daemonset/generic-kuberouter-all-features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ rules:
- services/status
verbs:
- update
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
10 changes: 9 additions & 1 deletion daemonset/generic-kuberouter-only-advertise-routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ rules:
- services/status
verbs:
- update

- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
10 changes: 9 additions & 1 deletion daemonset/generic-kuberouter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ rules:
- services/status
verbs:
- update

- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
9 changes: 9 additions & 0 deletions daemonset/kubeadm-kuberouter-all-features-dsr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ rules:
- services/status
verbs:
- update
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
9 changes: 9 additions & 0 deletions daemonset/kubeadm-kuberouter-all-features-hostport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ rules:
- services/status
verbs:
- update
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
9 changes: 9 additions & 0 deletions daemonset/kubeadm-kuberouter-all-features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ rules:
- services/status
verbs:
- update
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
9 changes: 9 additions & 0 deletions daemonset/kubeadm-kuberouter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ rules:
- services/status
verbs:
- update
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- get
- list
- watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/kube-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (kr *KubeRouter) Run() error {
informerFactory := informers.NewSharedInformerFactory(kr.Client, 0)
svcInformer := informerFactory.Core().V1().Services().Informer()
epInformer := informerFactory.Core().V1().Endpoints().Informer()
epSliceInformer := informerFactory.Discovery().V1().EndpointSlices().Informer()
podInformer := informerFactory.Core().V1().Pods().Informer()
nodeInformer := informerFactory.Core().V1().Nodes().Informer()
nsInformer := informerFactory.Core().V1().Namespaces().Informer()
Expand Down Expand Up @@ -177,7 +178,7 @@ func (kr *KubeRouter) Run() error {

if kr.Config.RunServiceProxy {
nsc, err := proxy.NewNetworkServicesController(kr.Client, kr.Config,
svcInformer, epInformer, podInformer, &ipsetMutex)
svcInformer, epSliceInformer, podInformer, &ipsetMutex)
if err != nil {
return fmt.Errorf("failed to create network services controller: %v", err)
}
Expand All @@ -186,7 +187,7 @@ func (kr *KubeRouter) Run() error {
if err != nil {
return fmt.Errorf("failed to add ServiceEventHandler: %v", err)
}
_, err = epInformer.AddEventHandler(nsc.EndpointsEventHandler)
_, err = epSliceInformer.AddEventHandler(nsc.EndpointSliceEventHandler)
if err != nil {
return fmt.Errorf("failed to add EndpointsEventHandler: %v", err)
}
Expand Down
Loading

0 comments on commit 327e894

Please sign in to comment.