【问题标题】:Why does nginx ingress minikube plugin hostPort work but hostPort does not work for any other plugin?为什么 nginx ingress minikube 插件 hostPort 工作,但 hostPort 不适用于任何其他插件?
【发布时间】:2020-01-23 13:30:54
【问题描述】:

在 minikube 中有一个 nginx 入口插件,它使用 80 和 443 的 hostPort。显然,来自外部的流量可以很好地到达这些端口。但是,如果您使用带有 hostPort: 9999 的容器创建 pod,例如 telnet $(minikube ip) 9999,则会得到以下结果:

Trying 192.168.99.165...
telnet: connect to address 192.168.99.165: Connection refused
telnet: Unable to connect to remote host

nginx 入口控制器有什么特别的作用吗?如果是这样,我还可以使用什么魔法?

请不要回答有关使用 NodePort 的问题。

【问题讨论】:

    标签: kubernetes minikube nginx-ingress


    【解决方案1】:

    没有什么特别的魔法。我怀疑您收到了 telnet 响应,因为在设置了 hostPort: 9999 的容器内的端口 9999 上没有任何监听。

    运行minikube ssh 并查看netstat -nlt,您将在那里看到您的端口9999。尝试在开放的 hostPort 上运行一个真正的服务监听,它应该可以工作,例如

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      labels:
        run: redis
      name: redis
    spec:
      replicas: 1
      selector:
        matchLabels:
          run: redis
      template:
        metadata:
          labels:
            run: redis
        spec:
          containers:
          - image: redis
            imagePullPolicy: Always
            name: redis
            ports:
            - containerPort: 6379
              hostPort: 6379
              protocol: TCP
    

    从我的终端:

    > telnet $(minikube ip) 6379
    Trying 192.168.99.189...
    Connected to 192.168.99.189.
    Escape character is '^]'.
    

    如果有在端口 9999 上监听,那么 Kubernetes 在主机和容器之间设置代理的方式可能存在问题。您可以查找docker-proxy 进程来检查:

    $ ps aux | grep docker-proxy
    root      3579  0.0  0.0   3668  1768 ?        Sl   14:43   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 10000 -container-ip 172.17.0.2 -container-port 10000
    root     19862  0.0  0.0   9240   476 pts/1    S+   16:21   0:00 grep docker-proxy
    root     23466  0.0  0.0   3668  1768 ?        Sl   15:20   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 18080 -container-ip 172.17.0.9 -container-port 18080
    root     23480  0.0  0.0   3668  1768 ?        Sl   15:20   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 443 -container-ip 172.17.0.9 -container-port 443
    root     23494  0.0  0.0   3668  1676 ?        Sl   15:20   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.17.0.9 -container-port 80
    root     25840  0.0  0.0   3668  1768 ?        Sl   15:24   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9999 -container-ip 172.17.0.10 -container-port 9999
    $ 
    

    【讨论】:

    • 将尝试您的示例并回复
    • @JoshWoodcock 进展如何?
    • 是的,你是对的,看来我正在使用的应用程序一定没有在那个端口上监听。我会进一步调查。
    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2021-08-20
    • 2018-10-27
    • 2019-01-16
    • 1970-01-01
    相关资源
    最近更新 更多