<p>I'm trying to automate a pod deployment and can't seem to figure out how to forward traffic from outside the cluster to the pod from the yaml config.</p>

<p>Access is only possible from localhost but not when accessing the master IP.
When separately applying 'kubectl port-forward --address 0.0.0.0 POD LISTEN_PORT:DEST_PORT' it works. </p>

<pre><code>apiVersion: v1
kind: Service
type:
metadata:
  labels:
    name: app1
  name: app1
spec:
  ports:
  - name: "80"
    port: 8888
    targetPort: 80
  selector:
    name: app1
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: app1
  name: app1
spec:
  containers:
  - image: nginx
    name: app1
    ports:
    - containerPort: 80
    resources:
      limits:
        cpu: 500m
        memory: "52428800"
      requests:
        cpu: 250m
        memory: "20971520"
  nodeSelector:
    slave: "one"
  restartPolicy: Never
</code></pre>

<blockquote>
<p>Kubernetes ServiceTypes allow you to specify what kind of Service you want. <strong>The default is ClusterIP</strong>.</p>
</blockquote>
<p><strong>ClusterIP</strong>: Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default ServiceType.</p>
<p><strong>NodePort</strong>: <strong>Exposes the Service on each Node’s IP at a static port</strong> (the NodePort). A ClusterIP Service, to which the NodePort <strong>Service routes, is automatically created</strong>. You’ll be able to contact the NodePort Service, from outside the cluster, by requesting <code>&lt;NodeIP&gt;:&lt;NodePort&gt;</code>.</p>
<p>You should updated service yaml as below to createa NodePort to access by NodePort</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    name: app1
  name: app1
spec:
  ports:
  - name: &quot;80&quot;
    port: 8888
    targetPort: 80
  selector:
    name: app1
  type: NodePort
</code></pre>
