helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
具有默认存储,如果没有存储,设置 persistence=false
helm upgrade --install mongodb-sharded bitnami/mongodb-sharded \
--namespace mongodb-sharded \
--create-namespace \
--set architecture=sharded \
--set shards=2 \
--set shardsvr.dataNode.replicaCount=3 \
--set configsvr.replicaCount=3 \
--set mongos.replicaCount=1 \
--set auth.rootPassword="123456" \
--set service.externalIPs[0]=172.30.10.86
## K8S 内部链接
mongodb-sharded.mongodb-sharded.svc.cluster.local
## 获取密码
export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace mongodb-sharded mongodb-sharded -o jsonpath="{.data.mongodb-root-password}" | base64 -d)
## 启动测试客户端
kubectl run --namespace mongodb-sharded mongodb-sharded-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mongodb-sharded:8.0.4-debian-12-r2 --command -- mongosh admin --host mongodb-sharded --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD
## K8S node 机器上本地转发测试
kubectl port-forward --namespace mongodb-sharded svc/mongodb-sharded 27017:27017 &
mongosh --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD