【问题标题】:Connect MongoDB compass client to the mongodb database inside kubernetes cluster将 MongoDB compass 客户端连接到 kubernetes 集群内的 mongodb 数据库
【发布时间】:2020-06-01 05:26:27
【问题描述】:

我在 kubernetes 集群中运行 mongo docker 容器服务。 来自外部的传入流量通过 ingress-nginx (https://kubernetes.github.io/ingress-nginx/) 负载均衡器路由到 mongo docker 容器服务。

应用程序按预期工作,我需要知道是否有一种方法可以将 MongoDB compass 客户端(我安装在本地计算机上)连接到正在运行的 mongodb 容器以轻松可视化数据。

我遇到了一些问题,因为容器在 kubernetes 中,并且中间有一个负载均衡器。

如果有人可以提供帮助,将会有很大帮助。谢谢

【问题讨论】:

    标签: mongodb kubernetes nginx-ingress mongodb-compass


    【解决方案1】:

    您可以使用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).
    
    

    【讨论】:

    • 您是否知道如何在 .yaml 文件中添加端口转发条目??
    • 抱歉没有得到这个问题。您能否进一步澄清一下要在哪个 .yaml 文件中添加的内容?您可以使用 containerPort 在部署容器上添加端口
    • apiVersion: v1 kind: Service metadata: name: mongo-srv spec: type: ClusterIP selector: app: auth-mongo ports: - name: auth-db protocol: TCP port: 27017 targetPort: 27017 @hoque:上面是创建 mongo-service 的代码,它放在 .YAML 文件中。想象一下,我需要进行端口转发,以便将 127.0.0.1:7000 流量路由到上面的 mongo-service。命令行工作正常。但我需要一种方法来使用 .YAML 文件来做同样的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 2019-12-30
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    相关资源
    最近更新 更多