Skip to content

Commit c4870fe

Browse files
authored
Disable nodeport auto allocation (#544)
disable nodeport auto allocation
1 parent b0ba111 commit c4870fe

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

topo/node/node.go

+6
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ func (n *Impl) CreateService(ctx context.Context) error {
515515
"app": n.Name(),
516516
},
517517
Type: "LoadBalancer",
518+
// Do not allocate a NodePort for this LoadBalancer. MetalLB
519+
// or the equivalent load balancer should handle exposing this service.
520+
// Large topologies may try to allocate more NodePorts than are
521+
// supported in default clusters.
522+
// https://kubernetes.io/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation
523+
AllocateLoadBalancerNodePorts: pointer.Bool(false),
518524
},
519525
}
520526
sS, err := n.KubeClient.CoreV1().Services(n.Namespace).Create(ctx, s, metav1.CreateOptions{})

topo/node/node_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"k8s.io/apimachinery/pkg/util/intstr"
1616
kfake "k8s.io/client-go/kubernetes/fake"
1717
"k8s.io/client-go/rest"
18+
"k8s.io/utils/pointer"
1819
)
1920

2021
func NewNR(impl *Impl) (Node, error) {
@@ -252,8 +253,9 @@ func TestService(t *testing.T) {
252253
TargetPort: intstr.FromInt(22),
253254
NodePort: 0,
254255
}},
255-
Selector: map[string]string{"app": "dev1"},
256-
Type: "LoadBalancer",
256+
Selector: map[string]string{"app": "dev1"},
257+
Type: "LoadBalancer",
258+
AllocateLoadBalancerNodePorts: pointer.Bool(false),
257259
},
258260
}},
259261
}, {
@@ -297,8 +299,9 @@ func TestService(t *testing.T) {
297299
TargetPort: intstr.FromInt(9339),
298300
NodePort: 0,
299301
}},
300-
Selector: map[string]string{"app": "dev2"},
301-
Type: "LoadBalancer",
302+
Selector: map[string]string{"app": "dev2"},
303+
Type: "LoadBalancer",
304+
AllocateLoadBalancerNodePorts: pointer.Bool(false),
302305
},
303306
}},
304307
}, {

0 commit comments

Comments
 (0)