deals my
deals my

Reputation: 133

GKE NodePort service refusing incoming traffic

I have created a Node port service in Google cloud with the following specification... I have a firewall rule created to allow traffic from 0.0.0.0/0 for the port '30100' ,I have verified stackdriver logs and traffic is allowed but when I either use curl or from browser to hit http://:30100 I am not getting any response. I couldn't proceed how to debug the issue also... can someone please suggest on this ?

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
        ports:
        - containerPort: 8080
---    
apiVersion: v1
kind: Service
metadata:
  name: nginxv1
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
    nodePort: 30100
  selector:
    app: nginxv1
  type: NodePort

Thanks.

Upvotes: 1

Views: 948

Answers (1)

Mr.KoopaKiller
Mr.KoopaKiller

Reputation: 3962

You need to fix the container port, it must be 80 because the nginx container exposes this port as you can see 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

Also, you need to create a firewall rule to permit the traffic to the node, as mentioned by @danyL in comments:

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

Get the node IP with the command

kubectl get nodes -owide

And them try to access the nginx page with:

curl http://<NODEIP>:30100

Upvotes: 1

Related Questions