mongodb - 将 MongoDB compass 客户端连接到 kubernetes 集群内的 mongodb 数据库
问题描述
我在 kubernetes 集群中运行 mongo docker 容器服务。来自外部的传入流量通过 ingress-nginx ( https://kubernetes.github.io/ingress-nginx/ ) 负载均衡器路由到 mongo docker 容器服务。
应用程序按预期工作,我需要知道是否有一种方法可以将 MongoDB 指南针客户端(我安装在本地计算机中)连接到正在运行的 mongodb 容器以轻松可视化数据。
我遇到了问题,因为容器在 kubernetes 内部,并且中间有一个负载均衡器。
如果有人可以提供帮助,将会有很大帮助。谢谢
解决方案
您可以使用端口转发
$ kubectl port-forward -h
Forward one or more local ports to a pod. This command requires the node to have 'socat' installed.
Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted.
If there are multiple pods matching the criteria, a pod will be selected automatically. The forwarding session ends
when the selected pod terminates, and rerun of the command is needed to resume forwarding.
Examples:
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward pod/mypod 5000 6000
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the
deployment
kubectl port-forward deployment/mydeployment 5000 6000
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the service
kubectl port-forward service/myservice 5000 6000
# Listen on port 8888 locally, forwarding to 5000 in the pod
kubectl port-forward pod/mypod 8888:5000
# Listen on port 8888 on all addresses, forwarding to 5000 in the pod
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000
# Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward pod/mypod :5000
Options:
--address=[localhost]: Addresses to listen on (comma separated). Only accepts IP addresses or localhost as a
value. When localhost is supplied, kubectl will try to bind on both 127.0.0.1 and ::1 and will fail if neither of these
addresses are available to bind.
--pod-running-timeout=1m0s: The length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one
pod is running
Usage:
kubectl port-forward TYPE/NAME [options] [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]
Use "kubectl options" for a list of global command-line options (applies to all commands).
推荐阅读
- django - 替代 django 模板中的范围函数。TemplateSyntaxError:无法解析剩余部分
- html - 在制作这个模型时需要帮助
- python - python inside()中的查询结果并将其转换为整数?
- python - 在 PyCharm 中配置 Flask 应用程序的调试器:“UnicodeDecodeError: 'utf-8' codec can't decode byte”
- php - 在 Drupal-7 中将 entityform 字段数据传递给 API
- google-bigquery - 相对于 BigQuery 中的另一个数组列对一个数组列进行排序
- .net-core - Octopus Deploy 中特定于环境的配置
- php - 在 Wordpress 中删除 404 状态
- c++ - 我什么时候会在基类中默认(而不是删除)复制和移动操作
- r - 轴限制和“浮动”点 - ggplot2