How to expose NodePort to internet on GCE

You can run kubectl in a terminal window (command or power shell in windows) to port forward the postgresql deployment to your localhost.

kubectl port-forward deployment/my-pg-deployment 5432:5432

While this command is running (it runs in the foreground) you can use pgAdmin to point to localhost:5432 to access your pod on the gke. Simply close the terminal once you are done using the pgadmin.


using NodePort as Service type works straight away e.g. like this:

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30080
      name: http
    - port: 443
      nodePort: 30443
      name: https
  selector:
    name: nginx

More details can be found in the documentation. The drawback of using NodePort is that you've to take care of integrating with your providers firewall by yourself. A starting port for that can also be found in the Configuring Your Cloud Provider's Firewalls section of the official documentation.

For GCE opening up the above for publicly on all nodes could look like:

gcloud compute firewall-rules create myservice --allow tcp:30080,tcp:30443

Once this is in place your services should be accessable through any of the public IPs of your nodes. You'll find them with:

gcloud compute instances list