[英]Connect MongoDB compass client to the mongodb database inside kubernetes cluster
I am running a mongo docker container service inside a kubernetes cluster.我在 kubernetes 集群内运行 mongo docker 容器服务。 Incoming traffic from outside is routed via ingress-nginx ( https://kubernetes.github.io/ingress-nginx/ ) load balancer to the mongo docker container service.来自外部的传入流量通过 ingress-nginx ( https://kubernetes.github.io/ingress-nginx/ ) 负载均衡器路由到 mongo Z05B6053C41A2130AFD6FC3BE158 容器服务。
Application is working as expected and I need to know whether there is a way I can connect the MongoDB compass client (which i installed in my local machine) to the running mongodb container to visualize the data easily.应用程序按预期工作,我需要知道是否有一种方法可以将 MongoDB 罗盘客户端(我安装在本地机器上)连接到正在运行的 mongodb 容器以轻松可视化数据。
I am having issues since the container is inside kubernetes and there is a load balancer in between.我遇到了问题,因为容器在 kubernetes 内部,并且中间有一个负载均衡器。
Would be of great help if someone could assist.如果有人可以提供帮助,将会有很大帮助。 Thanks谢谢
You can use port-forward您可以使用端口转发
$ 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).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.