我正在GKE服务上进行部署,当我尝试访问该页面时,发现消息
ERR_CONNECTION_REFUSED
我已经为部署定义了负载平衡服务,其配置如下。
这是用于部署的.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: bonsai-onboarding
spec:
selector:
matchLabels:
app: bonsai-onboarding
replicas: 2
template:
metadata:
labels:
app: bonsai-onboarding
spec:
containers:
- name: bonsai-onboarding
image: "eu.gcr.io/diaphanum/onboarding-iocash-master_web:v1"
ports:
- containerPort: 3000
这是服务.yaml文件。
apiVersion: v1
kind: Service
metadata:
name: lb-onboarding
spec:
type: LoadBalancer
selector:
app: bonsai-onboarding
ports:
- protocol: TCP
port: 3000
targetPort: 3000
这工作正常,并且在GKE中都是绿色的:)
kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/bonsai-onboarding-8586b9b699-flhbn 1/1 Running 0 3h23m
pod/bonsai-onboarding-8586b9b699-p9sn9 1/1 Running 0 3h23m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP XX.xx.yy.YY <none> 443/TCP 29d
service/lb-onboarding LoadBalancer XX.xx.yy.YY XX.xx.yy.YY 3000:32618/TCP 3h
然后,当我尝试连接错误时是ERR_CONNECTION_REFUSED
我认为与网络有关,因为y从本地计算机进行了下一次测试
Ping [load balancer IP] ---> Correct
Telnet [Load Balancer IP] 3000 ---> Correct
我从Cloud Shell将端口3000转发到8080,然后在其他cloudShell中创建Curl http://localhost:8080,然后正常工作。
对这个问题有任何想法吗?
预先感谢
答案 0 :(得分:2)
由于您的映像无法访问,我对您的部署进行了一些更改以在群集上进行检查:
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: bonsai-onboarding
spec:
selector:
matchLabels:
app: bonsai-onboarding
replicas: 2
template:
metadata:
labels:
app: bonsai-onboarding
spec:
containers:
- name: bonsai-onboarding
image: nginx:latest
ports:
- containerPort: 80
服务:
apiVersion: v1
kind: Service
metadata:
name: lb-onboarding
spec:
type: LoadBalancer
selector:
app: bonsai-onboarding
ports:
- protocol: TCP
port: 3000
targetPort: 80
它可以立即使用:
kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/bonsai-onboarding-7bdf584499-j2nv7 1/1 Running 0 6m58s
pod/bonsai-onboarding-7bdf584499-vc7kh 1/1 Running 0 6m58s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.XXX.XXX.1 <none> 443/TCP 8m35s
service/lb-onboarding LoadBalancer 10.XXX.XXX.230 35.XXX.XXX.235 3000:31637/TCP 67s
我可以通过任何IP访问35.XXX.XXX.235:3000
:
Welcome to nginx!
...
Thank you for using nginx.
您可以使用以下命令检查您的应用是否可以访问:
nmap -Pn $(kubectl get svc lb-onboarding -o jsonpath='{.status.loadBalancer.ingress[*].ip}')
也许是图像配置中出现“ ERR_CONNECTION_REFUSED”问题的原因?我发现您的部署和负载均衡器配置没有问题。
答案 1 :(得分:1)
确保在部署/状态集/ pod的规范中定义了containerPort,并且应用程序正在该端口上侦听。另外,请确保您的防火墙规则没有阻止节点端口。
gcloud compute firewall-rules create myservice --allow tcp:3000