【问题标题】:Unable to access a NodePort service on Minikube running on AWS无法访问在 AWS 上运行的 Minikube 上的 NodePort 服务
【发布时间】:2021-09-20 23:45:29
【问题描述】:

安装 minikube 后,我一直在 AWS 实例(ubuntu 20.04)上从官方 Kubernetes 网站上学习教程:

https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/

我已经从安全组公开了节点端口 - 如下所述的 31055,但我仍然无法远程访问该应用程序。当我尝试将 curl 与应用程序的 url 一起使用时,从 ssh 访问远程服务器,我可以获得我正在寻找的结果,但我无法从浏览器访问它。

我尝试使用 docker 驱动程序启动 minikube,但也没有驱动程序,但我仍然面临同样的问题。
知道如何解决这个问题吗?
谢谢

在服务的完整 yaml 下方:

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2021-04-10T15:47:01Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:spec:
        f:externalTrafficPolicy: {}
        f:ports:
          .: {}
          k:{"port":8080,"protocol":"TCP"}:
            .: {}
            f:port: {}
            f:protocol: {}
            f:targetPort: {}
        f:selector:
          .: {}
          f:run: {}
        f:sessionAffinity: {}
        f:type: {}
    manager: kubectl-expose
    operation: Update
    time: "2021-04-10T15:47:01Z"
  name: example-service
  namespace: default
  resourceVersion: "521"
  uid: e19ea9a3-9700-4e37-b810-defb7e4fee67
spec:
  clusterIP: 10.99.135.151
  clusterIPs:
  - 10.99.135.151
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 31055
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    run: load-balancer-example
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

【问题讨论】:

  • 浏览器的错误信息是什么?
  • @Matt 我得到“无法连接 Firefox 无法建立与...的服务器的连接”
  • I tried to start minikube [...] without a driver 是什么意思?你的意思是你没有使用--driver 标志还是你使用了--driver=None
  • @Matt 我已经尝试过使用 --driver=docker 和 --driver=none 的教程,但在这两种情况下我遇到了同样的问题。
  • 使用 --driver=none 启动它,然后使用 netstat 或 ss 检查 nodePort 是否打开并在 0.0.0.0 上侦听

标签: minikube


【解决方案1】:
So one solution is:

apt install conntrack
minikube start --driver=none

but a much better solution is start minikube the normal way, then do this - I've used all zeros here but you could get granular with your security as appropriate for your environment.

kubectl port-forward --address 0.0.0.0 svc/{your service name} {external port to the Internet}:{your service port, the port your app is listening on in it's container}

for example, if my service is named badstore and is listening on 80

kubectl port-forward --address 0.0.0.0 svc/badstore 8888:80


【讨论】:

  • 虽然这些命令可能会解决问题,但including an explanation 说明它们如何以及为什么这样做将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
猜你喜欢
  • 2020-12-15
  • 2020-10-04
  • 1970-01-01
  • 2018-06-02
  • 2021-06-27
  • 2018-09-27
  • 1970-01-01
  • 1970-01-01
  • 2018-10-29
相关资源
最近更新 更多