MongoDB 实例位于 Azure Kubernetes Pod 中。我想从外部安全地访问这个 headless mongodb。我已经在虚拟机中安装了 compass 并将连接字符串粘贴到 mongodb compass 中,VM 和 kubernete 都在同一网络中,但它显示 getaddrinfo ENOTFOUND 错误。在连接字符串中有副本集名称 rs0 和 ssl=false
最佳答案
什么是 headless 服务?
With a Headless Service, clients can connect to it’s pods by connecting to the service’s DNS name. But using headless services, DNS returns the pod’s IPs and client can connect directly to the pods instead via the service proxy. read more : https://blog.knoldus.com/what-is-headless-service-setup-a-service-in-kubernetes/
您无法从另一个虚拟机连接到 AKS 中运行的 headless 服务。
您可以通过负载均衡器的NodePort公开您的服务,并从另一个虚拟机进一步访问。
NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting :.
LoadBalancer: Exposes the Service externally using a cloud provider's load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.
引用号:https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer
或者您可以使用入口 Controller 将服务公开到集群之外并对其进行管理。
关于保护开放服务,如果使用入口 Controller ,您可以将 IP 列入白名单。
或者直接在服务中将 IP 范围列入白名单
loadBalancerSourceRanges:
- "143.231.0.0/16"
引用:https://aws.amazon.com/premiumsupport/knowledge-center/eks-cidr-ip-address-loadbalancer/
关于mongodb - 如何从 mongodb compass gui 访问 azure kubernete pod mongodb 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71613608/