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

AMe*_*dis 3 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
Run Code Online (Sandbox Code Playgroud)

这是我的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
Run Code Online (Sandbox Code Playgroud)

这是我的kubectl get pods输出

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

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

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

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

Arg*_*dhu 6

IP10.152.183.11 无法CLUSTER-IP从集群外部(即浏览器)访问。您应该使用在主机系统上打开的位置http://localhost:3169531695NodePort

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

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

microk8s.kubectl expose deployment/kubernetes-bootcamp --type=NodePort --port 8080
Run Code Online (Sandbox Code Playgroud)