kubeblocks icon indicating copy to clipboard operation
kubeblocks copied to clipboard

Specify HostPort when creating cluster

Open shanshanying opened this issue 3 months ago • 7 comments

Discussed in https://github.com/apecloud/kubeblocks/discussions/9785

Originally posted by dudizimber September 30, 2025 We have a use case where we deploy multiple databases of the same type in a single k8s cluster. The database requires external access via HostNetwork. In our specific setup, the service port cannot be randomly generated and has to be specified when creating the Cluster, since not all databases will listen to the same port, even if they are of the same type.

While trying it out, I saw that the PortManager is the one that allocates a random port (not really random, but also not known before the allocation), and it does so by storing the allocated ports in a single configmap for the whole cluster, in the structure:

<pod>-<container>-<portName>: <portNumber>

Hence, in my interpretation, all databases in the k8s cluster of the same type (pod name) will receive the same port, as it always checks the name and returns the same port if it exists.

My question is if there's a way to accomplish that without modifying the operator. Meaning that, when using HostNetwork, the port could be defined on the Cluster manifest.

shanshanying avatar Oct 20 '25 09:10 shanshanying

@dudizimber we can discuss the feature and impl here

cc @leon-inf

shanshanying avatar Oct 20 '25 09:10 shanshanying

@dudizimber here is my understanding of the whole thing:

  1. users specify host port when creating cluster
  2. KB uses the ports insteading of allocating ports on demand

But one constraint still holds that Pods/Replicas from the same compont, e.g. falkordb, still share the same set of ports (as it is in KB now). Is it acceptable ?

shanshanying avatar Oct 20 '25 10:10 shanshanying

@dudizimber here is my understanding of the whole thing:

  1. users specify host port when creating cluster
  2. KB uses the ports insteading of allocating ports on demand

But one constraint still holds that Pods/Replicas from the same compont, e.g. falkordb, still share the same set of ports (as it is in KB now). Is it acceptable ?

I believe that's not only acceptable but also required.

dudizimber avatar Oct 20 '25 10:10 dudizimber

The question is whether the ideal place to put a hostPort parameter is in the componentSpecs or under componentSpecs.*.instances

dudizimber avatar Oct 20 '25 10:10 dudizimber

in my understanding, place it to the componentSpecs level is better, it is a componet-layer setting. @leon-inf what do you think.

shanshanying avatar Oct 21 '25 02:10 shanshanying

in my understanding, place it to the componentSpecs level is better, it is a componet-layer setting. @leon-inf what do you think.

Yeah, adding the parameter to 'spec.componentSpecs.network' is ideal. Meanwhile, there are some special details that should be taken into account, and I'll provide this feature in the next few days.

leon-inf avatar Oct 21 '25 04:10 leon-inf

in my understanding, place it to the componentSpecs level is better, it is a componet-layer setting. @leon-inf what do you think.

Yeah, adding the parameter to 'spec.componentSpecs.network' is ideal. Meanwhile, there are some special details that should be taken into account, and I'll provide this feature in the next few days.

@leon-inf I'm working on this PR https://github.com/apecloud/kubeblocks/pull/9820 if you want to guide me.

dudizimber avatar Oct 21 '25 06:10 dudizimber

This issue has been marked as stale because it has been open for 30 days with no activity

github-actions[bot] avatar Nov 24 '25 00:11 github-actions[bot]