【问题标题】:Cannot access Microk8s service from browser using NodePort service无法使用 NodePort 服务从浏览器访问 Microk8s 服务
【发布时间】:2020-11-05 03:18:09
【问题描述】:

我根据这里的步骤https://ubuntu.com/kubernetes/install#single-node在我的ubuntu机器上安装了microk8s

然后我按照 kubernetes 官方教程,创建并暴露了一个这样的部署

microk8s.kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8083

这是我的kubectl get services 输出

akila@ubuntu:~$ microk8s.kubectl get services
NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.152.183.1    <none>        443/TCP          25h
kubernetes-bootcamp   NodePort    10.152.183.11   <none>        8083:31695/TCP   17s

这是我的kubectl get pods 输出

akila@ubuntu:~$ microk8s.kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-6f6656d949-rllgt   1/1     Running   0          51m

但我无法使用 http://localhost:8083 或使用 http://10.152.183.11:31695 从浏览器访问服务

当我尝试 http://localhost:31695 时,我得到了 ERR_CONNECTION_REFUSED。

如何从我的浏览器访问这个“kubernetes-bootcamp”服务? 我错过了什么吗?

【问题讨论】:

  • 您应该使用http://localhost:31695访问应用程序
  • @DashrathMundkar 我收到 ERR_CONNECTION_REFUSED

标签: kubernetes kubernetes-ingress kubernetes-pod microk8s


【解决方案1】:

IP 10.152.183.11CLUSTER-IP,不能从集群外部(即浏览器)访问。您应该使用http://localhost:31695,其中31695 是在主机系统上打开的NodePort

gcr.io/google-samples/kubernetes-bootcamp:v1 图像的容器需要侦听端口 8083,因为您将它暴露在该端口上。仔细检查,否则会导致ERR_CONNECTION_REFUSED 错误。

如果容器正在侦听端口8080,则使用以下命令公开该端口

microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8080

【讨论】:

  • 我收到 ERR_CONNECTION_REFUSED
  • 该图像有什么应用程序?它是否监听 8083 端口?
  • 你是对的。它列出到 8080。当我暴露端口 8080 时,我可以加载页面
【解决方案2】:

试试这个

kubectl port-forward <pod_name> <local_port>:<pod_port> 

然后访问http://localhost:&lt;local_port&gt;

【讨论】:

    猜你喜欢
    • 2021-10-12
    • 1970-01-01
    • 2018-06-23
    • 2021-06-27
    • 2018-04-01
    • 2017-12-01
    • 2017-07-21
    • 2020-11-13
    • 2021-10-04
    相关资源
    最近更新 更多