每次我试图访问机器上的NodePort时,都会说“错误连接被拒绝”。我不明白,因为我在网上读到的例子意味着我可以在我的笔记本上运行Desktop,连接到集群,并通过它们的nodeport访问服务。
我的机器:
k3s和minikube进行测试,结果相似)Kubernetes配置:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: ngnix-service
spec:
selector:
app: nginx
type: NodePort
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30007输出和cURL测试:
PS C:\Users\ME\nginx> kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 169m
ngnix-service NodePort 10.108.214.243 <none> 80:30007/TCP 7m19s
PS C:\Users\ME\nginx> curl.exe http://localhost:30007
curl: (7) Failed to connect to localhost port 30007: Connection refused我也尝试过使用节点ip:
PS C:\Users\ME\nginx> kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
docker-desktop Ready master 6d v1.19.7 192.168.65.4 <none> Docker Desktop 5.10.25-linuxkit docker://20.10.5
PS C:\Users\ME\nginx> curl.exe http://192.168.65.4:30007
curl: (7) Failed to connect to 192.168.65.4 port 30007: Timed out当我试图从浏览器(Chrome)访问NodePort时,我得到了相同的响应。ERR_CONNECTION_REFUSED
我遗漏了什么吗?为什么所有的NodePorts都无法访问?
发布于 2021-04-19 19:13:20
Kubernetes在本地运行,仍然在其内部网络上运行。
curl.exe http://192.168.65.4:30007
在这里,您使用的IP地址是内部Kubernetes网络。您必须公开您的Kubernetes服务,以便它获得集群-外部地址。
见本部分:
EXTERNAL-IP
<none>您通常使用type: Loadbalancer的服务在集群之外公开服务,或者使用侵入网关。
有关如何将服务从回答更改为type: LoadBalancer,以便将其公开给本地主机,请参阅此type: LoadBalancer。
访问服务的最简单的方法是使用kubectl port-forward。
kubectl port-forward ngnix-service 8080:80然后您可以在localhost:8080上访问它。
发布于 2021-11-09 19:22:27
不知道这对谁都有帮助。我遇到了类似的问题,在这些问题中,正确地创建了NodePort,入口点指向正确的containerPort和IP。然而,我没有能够卷曲NodePort。经过一天的搜寻,这里是我的解锁。我想我会分享给人们寻找的痛苦。
运行后(对于mac)
rm -rf ~/Library/Group\ Containers/group.com.docker/pki/对于windows,文件夹为C:/ProgramData/DockerDesktop/pki
然后重新启动停靠桌面。
源(https://github.com/docker/for-mac/issues/3594#issuecomment-621487150)
https://stackoverflow.com/questions/67167114
复制相似问题