我根据这里的步骤在我的 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:8083
或 http://10.152.183.11:31695
从我的浏览器访问该服务
当我尝试访问 http://localhost:31695 时,我得到了 ERR_CONNECTION_REFUSED。
如何从我的浏览器访问这个“kubernetes-bootcamp”服务? 我错过了什么吗?
最佳答案
IP 10.152.183.11
是 CLUSTER-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/