Trouble accessing nginx deployment externally

4/22/2018

I can curl an exposed nginx deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
      tr: frnt
  template:
    metadata:
      labels:
        app: nginx
        tr: frnt
    spec:
      containers:
        - image: nginx
          name: nginx
          ports:
            - containerPort: 80
      restartPolicy: Always 

----

apiVersion: v1
kind: Service
metadata:
  name: web-dep-nodeport-service
spec:
  selector:
    tr: frnt
  ports:
    - nodePort: 30000
      port: 80
  type: NodePort     

on a node, with success:

user@gke-cluster-1-default-pool-xxxx ~ $ curl -Lvso /dev/null http://localhost:30000
* Rebuilt URL to: http://localhost:30000/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 30000 (#0)
> GET / HTTP/1.1
> Host: localhost:30000
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.9.15
< Date: Sun, 22 Apr 2018 04:40:24 GMT
< Content-Type: text/html
< Content-Length: 612
< Last-Modified: Tue, 19 Apr 2016 17:27:46 GMT
< Connection: keep-alive
< ETag: "xxxxx"
< Accept-Ranges: bytes
< 
{ [612 bytes data]
* Connection #0 to host localhost left intact

But when trying the same command on an external machine, using the node EXTERNAL_IP (from gcloud compute instances list), I get:

$ curl -Lvso /dev/null  http://x.x.x.x:30000 &> result.txt &
$ cat result.txt 
* Rebuilt URL to: http://x.x.x.x:30000/
*   Trying x.x.x.x...
* connect to x.x.x.x port 30000 failed: Connection timed out
* Failed to connect to x.x.x.x port 30000: Connection timed out
* Closing connection 0

I can ping the EXTERNAL_IP with success:

ping -c 2 x.x.x.x
PING x.x.x.x (x.x.x.x) 56(84) bytes of data.
64 bytes from x.x.x.x: icmp_seq=1 ttl=56 time=32.4 ms
64 bytes from x.x.x.x: icmp_seq=2 ttl=56 time=33.7 ms

--- x.x.x.x ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 32.456/33.099/33.742/0.643 ms

What can I do here to expose the nodePort externally?

-- category
deployment
google-cloud-networking
google-compute-engine
google-kubernetes-engine
kubernetes

1 Answer

4/22/2018

This was solved by creating a firewall rule:

gcloud compute firewall-rules create nginx-rule --allow tcp:30000

-- category
Source: StackOverflow