Open Pieerot opened 5 days ago
In Kubeblocks 0.9.0, MongoDB support initialization with host networking, enabling access through the host IP outside of Kubernetes. Before using this feature, you should upgrade the MongoDB addon to version 0.9.1 and create a new cluster with the following commands: ` helm repo add kubeblocks-addons https://apecloud.github.io/helm-charts
helm upgrade -i kb-addon-mongodb kubeblocks-addons/mongodb -n kb-system --version 0.9.1
helm install your-cluster-name kubeblocks-addons/mongodb-cluster --version 0.9.1 --set hostnetwork=enable `
In Kubeblocks 0.9.0, MongoDB support initialization with host networking, enabling access through the host IP outside of Kubernetes. Before using this feature, you should upgrade the MongoDB addon to version 0.9.1 and create a new cluster with the following commands: ` helm repo add kubeblocks-addons https://apecloud.github.io/helm-charts
helm upgrade -i kb-addon-mongodb kubeblocks-addons/mongodb -n kb-system --version 0.9.1
helm install your-cluster-name kubeblocks-addons/mongodb-cluster --version 0.9.1 --set hostnetwork=enable `
Thank you for your reply, but it seems that the host network cannot meet my needs In fact, I hope to configure a separate domain for each pod in a replicaset MongoDB, such as [example. mongo-01. com, example. mongo-02...], and could connect to MongoDB through multiple domains.
The main issue is that the host in the replicaset's conf is the headless domain of the service. the MongoDB driver will listens to the cluster topology and attempts to connect to these headless domains. I have attached the specific rs.conf() below. The initialization of the replica cluster and the member's joining and leaveing of cluster are managed by Lorry, seemingly only using headless domain names as hosts. This will result in the inability to connect to MongoDB outside the k8s cluster.
func (c *Cluster) GetMemberAddrWithPort(member Member) string {
addr := c.GetMemberAddr(member)
return fmt.Sprintf("%s:%s", addr, member.DBPort)
}
func (c *Cluster) GetMemberAddr(member Member) string {
if member.UseIP {
return member.PodIP
}
clusterDomain := viper.GetString(constant.KubernetesClusterDomainEnv)
clusterCompName := ""
index := strings.LastIndex(member.Name, "-")
if index > 0 {
clusterCompName = member.Name[:index]
}
return fmt.Sprintf("%s.%s-headless.%s.svc.%s", member.Name, clusterCompName, c.Namespace, clusterDomain)
}
mongo-jy-test09-mongodb [direct: primary] admin> rs.conf()
{
_id: 'mongo-jy-test09-mongodb',
version: 14,
term: 12,
members: [
{
_id: 0,
host: 'mongo-jy-test09-mongodb-0.mongo-jy-test09-mongodb-headless.mongo-jy-test09.svc.cluster.local:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long("0"),
votes: 1
},
{
_id: 1,
host: 'mongo-jy-test09-mongodb-1.mongo-jy-test09-mongodb-headless.mongo-jy-test09.svc.cluster.local:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long("0"),
votes: 1
},
{
_id: 2,
host: 'mongo-jy-test09-mongodb-2.mongo-jy-test09-mongodb-headless.mongo-jy-test09.svc.cluster.local:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 2,
tags: {},
secondaryDelaySecs: Long("0"),
votes: 1
}
],
protocolVersion: Long("1"),
writeConcernMajorityJournalDefault: true,
settings: {
chainingAllowed: true,
heartbeatIntervalMillis: 2000,
heartbeatTimeoutSecs: 10,
electionTimeoutMillis: 10000,
catchUpTimeoutMillis: -1,
catchUpTakeoverDelayMillis: 30000,
getLastErrorModes: {},
getLastErrorDefaults: { w: 1, wtimeout: 0 },
replicaSetId: ObjectId("67161fede62d649f8c72cf60")
}
}
Yes, you're right. The MongoDB cluster topology is managed by Lorry, which supports headless services and host networking to configure the replicaset. However, it cannot recognize or use domains outside of Kubernetes. Is it possible to use the host network to initialize the MongoDB replicaset and use an external domain that points to the host IP?
Yes, you're right. The MongoDB cluster topology is managed by Lorry, which supports headless services and host networking to configure the replicaset. However, it cannot recognize or use domains outside of Kubernetes. Is it possible to use the host network to initialize the MongoDB replicaset and use an external domain that points to the host IP?
Thank you for your suggestion, I will try this solution.
I have upgrade kbcli and kubebnlocks to v0.9.1. But I encountered some problems when creating a mongo cluster using the following command.
helm install hosttest kubeblocks-addons/mongodb-cluster --version 0.9.1 --set mode=replicaset --set replicas=3 --set hostnetwork=enabled
The hostnetwork doesn't seem to be working。
hosttest-mongodb [direct: primary] admin> rs.config()
{
_id: 'hosttest-mongodb',
version: 5,
term: 1,
members: [
{
_id: 0,
host: 'hosttest-mongodb-0.hosttest-mongodb-headless.mongotest091.svc:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 2,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
},
{
_id: 1,
host: 'hosttest-mongodb-1.hosttest-mongodb-headless.mongotest091.svc:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
},
{
_id: 2,
host: 'hosttest-mongodb-2.hosttest-mongodb-headless.mongotest091.svc:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long('0'),
votes: 1
}
],
protocolVersion: Long('1'),
writeConcernMajorityJournalDefault: true,
settings: {
chainingAllowed: true,
heartbeatIntervalMillis: 2000,
heartbeatTimeoutSecs: 10,
electionTimeoutMillis: 10000,
catchUpTimeoutMillis: -1,
catchUpTakeoverDelayMillis: 30000,
getLastErrorModes: {},
getLastErrorDefaults: { w: 1, wtimeout: 0 },
replicaSetId: ObjectId('6728bb5712f158c7b75453d9')
}
}
I noticed that the hostnetwork only works when useLegacyCompDef=true
, so I tried to set useLegacyCompDef=true, but the precheck of the created cluster failed with the following message.
Status:
Conditions:
Last Transition Time: 2024-11-04T12:26:51Z
Message: ClusterVersion.apps.kubeblocks.io "6.0.16" not found
Reason: PreCheckFailed
Status: False
Type: ProvisioningStarted
What should I do next? Looking forward to your reply.
By the way, I believe that using a host network can only meet the needs of testing and development, and there may be port conflicts or other risks in production practice. If there is another more graceful solution, it would be very helpful to me.
I apologize for the issue and appreciate your response regarding the problem. The MongoDB addon was recently upgraded to a new API, and the host network is not functioning normally. We have fixed this in the new chart. Please upgrade using the same commands as before. The host ports are managed by KubeBlocks, which ensures that there are no conflicts with resources it controls. ` helm repo add kubeblocks-addons https://apecloud.github.io/helm-charts
helm upgrade -i kb-addon-mongodb kubeblocks-addons/mongodb -n kb-system --version 0.9.1
helm install your-cluster-name kubeblocks-addons/mongodb-cluster --version 0.9.1 --set hostnetwork=enabled,mode=replicaset ` I think a better solution would be to have Kubeblocks support clusters created with domains specified for each replica. However, there is a challenge with domain management outside of Kubernetes in situations such as scale-in and scale-out. Kubeblocks cannot manage resources outside of Kubernetes, and not everyone has a management system for domains.
Another possible solution is to use the headless domain and configure IP mapping for this domain outside Kubernetes. This way, the domain name remains consistent inside and outside the cluster, though the IP addresses differ. (This might work, but i am not sure..)
Describe the bug when i try to connect to a deployed replicaset mode mongodb by golang mongo driver, the driver will monitor cluster topology and update topology to headless domain. But at outside of k8s cluster i can't resolve the headless domain, so it will occur error which "no such host".
I have expose the service by NodePort service, And if I directly connect a pod, it can work properly.
I noticed that Lorry uses the headless domain component Replicset topology. Is there any configuration to use custom external domains for component topology, or is there any other way for me to connect to MongoDB outside the k8s cluster?
To Reproduce Steps to reproduce the behavior:
func main() {
}