<p>I've setup a NodePort service using the following config:</p>

<p><strong>wordpress-service.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: wordpress
  name: wordpress
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app: wordpress
</code></pre>

<p>Is this sufficient to access the service externally, if so how can I now access the service? What details do I need - and how do I determine them - for example node IP.</p>

<blockquote>
  <p>For Kubernetes on GCE:</p>
</blockquote>

<p>We had the same question regarding services of type NodePort: How do we access node port services from our own host?</p>

<p>@ivan.sim 's answer (nodeIp:nodePort) is on mark however, you still wouldn't be able to access your service unless you add a firewall ingress (inbound to google cloud) traffic rule on the VPC network console to allow your host to be able to access your compute node</p>

<p><a href="https://i.stack.imgur.com/8zFOt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8zFOt.png" alt="enter image description here"></a>
the above rule is dangerous and should be used only during development</p>

<p>You can find the node port using either the Google Cloud console or by running subsequent kubectl commands to find out the node running your pod which has your container. i.e <code>kubectl get pods , kubectl describe pod your-pod-name, kubectl describe node node-that-runs-you-pod</code> .status.addresses has your ExternalIP</p>

<p>It would be great if we could extract the node ip running our container in the pod using only a <code>label/selector</code> and a few line of commands, so here is what we did, in this case our selector is <code>app: your-label</code>:</p>

<pre><code>$ nodename=$(kubectl get pods -o jsonpath='{.items[?(@.metadata.labels.app=="your-label")].spec.nodeName}')

$ nodeIp=$(kubectl get nodes -o jsonpath='{.items[?(@.metadata.name=="'$(echo $nodename)'")].status.addresses[?(@.type=="ExternalIP")].address}')

$ echo nodeIp
</code></pre>

<p><strong>notice</strong>: we used json path to extract the information we desired, for more on json path see: <a href="https://kubernetes.io/docs/user-guide/jsonpath/" rel="noreferrer">json path</a></p>

<p>You could certainly turn this into a script that takes a label/selector as input and outputs an external ip of the node running your container !!!</p>

<p>To get the nodeport just type:</p>

<pre><code>$ kubectl get services
</code></pre>

<p>under the <strong>PORT(S)</strong> columns you will see something like tagetPort:nodePort. this nodeport  is what you want .</p>

<pre><code>nodeIp:nodePort
</code></pre>
