kubernetes - 无法使用 NodePort 服务从浏览器访问 Microk8s 服务

标签 kubernetes kubernetes-ingress kubernetes-pod microk8s

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

然后我按照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:8083http://10.152.183.11:31695 从我的浏览器访问该服务

>

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

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

最佳答案

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

关于kubernetes - 无法使用 NodePort 服务从浏览器访问 Microk8s 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62918016/

相关文章:

kubernetes - 要求BAN要求的Http 400

kubernetes - 在 k3s 上使用 traefik ingress 生成重定向?

kubernetes - 如何在特定 namespace 中创建K8S部署?

kubernetes - 1 个节点存在 Pod 无法容忍的污点 {node.kubernetes.io/disk-Pressure : },

docker - 代理背后的 Kubernetes Docker 容器

macos - LivenessProbe 失败,但端口转发在同一个端口上工作

nginx - 无法以非root用户身份运行nginx容器

azure - 如何在service-node-port-range默认范围之外的NodePort上启动kubernetes服务?

Kubernetes:使用 HTTPS 通信内部服务

kubernetes - 我正在尝试将 externalname 与 Nginx-Controller 的 nodeport 服务一起使用,但我得到 502 Bad Gateway