<p>My objective: To expose a pod's(running angular image) <code>port</code> so that I can <strong>access it from the host machine's browser</strong>.         </p>

<p>service.yml:            </p>

<pre><code>apiVersion: v1
kind: Service
metadata:  
  name: my-frontend-service
spec:
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 8000
    targetPort: 4200
</code></pre>

<p>Pod's yml:                </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: angular.frontend
  labels:
    app: MyApp
spec:
  containers:
  - name: angular-frontend-demo
    image: angular-frontend-image
    ports:
    - name: nodejs-port
      containerPort: 4200
</code></pre>

<p>Weird thing is that doing <code>kubectl port-forward pod/angular.frontend 8000:4200</code> works. However, my objective is to write that in <code>service.yml</code></p>

<p>Use Nodeport:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:  
  name: my-frontend-service
spec:
  selector:
    app: MyApp
  type: NodePort
  ports:
  - protocol: TCP
    port: 8000
    targetPort: 4200
    nodePort: 30001
</code></pre>

<p>then you can access the service on nodeport 30001 on any node of the cluster. </p>

<p>For example the machine name is node01 , you can then do curl <a href="http://node01:30001" rel="nofollow noreferrer">http://node01:30001</a></p>
