GKE NodePort服务拒绝传入流量

时间:2020-07-18 22:42:03

标签: kubernetes deployment google-kubernetes-engine

我已按照以下规范在Google云中创建了节点端口服务...我创建了防火墙规则,以允许端口'30100'的流量从0.0.0.0/0起,我已验证了堆栈驱动程序日志,并且允许,但是当我使用curl或从浏览器访问http://:30100时,没有任何反应。我也无法继续调试该问题...有人可以对此提出建议吗?

DefinePlugin

谢谢。

1 个答案:

答案 0 :(得分:1)

您需要修复容器端口,它必须为80,因为nginx容器公开了该端口,如您所见here

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxv1
  template:
    metadata:
      labels:
        app: nginxv1
    spec:
      containers:
      - name: nginx
        image: nginx:latest
---    
apiVersion: v1
kind: Service
metadata:
  name: nginxv1
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30100
  selector:
    app: nginxv1
  type: NodePort

此外,您还需要创建防火墙规则以允许流量进入节点,如@danyL在评论中所述:

gcloud compute firewall-rules create test-node-port --allow tcp:30100

使用命令获取节点IP

kubectl get nodes -owide

他们尝试通过以下方式访问nginx页面:

curl http://<NODEIP>:30100