<p>I am trying to expose a deployment I made on minikube:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-test
  labels:
    app: debian
spec:
  replicas: 1
  selector:
    matchLabels:
      app: debian
  strategy: {}
  template:
    metadata:
      labels:
        app: debian
    spec:
      containers:
      - image: agracia10/debian_bash:latest
        name: debian
        ports:
        - containerPort: 8006
        resources: {}
      restartPolicy: Always
status: {}
</code></pre>
<p>I decided to follow was is written on <a href="https://stackoverflow.com/questions/46245508/how-create-service-on-minikube-with-yaml-configuration-which-accessible-from-hos">here</a></p>
<p>I try to expose the deployment using the following command:</p>
<pre><code>kubectl expose pod deployment-test-8497d6f458-xxhgm --type=NodePort --port=8080 --target-port=80
</code></pre>
<p>but when I try to then access the service created by the expose command, using the url provided by</p>
<pre><code>minikube service deployment-test-8497d6f458-xxhgm --url
</code></pre>
<p>it throws an error using packetsender to try and connect to the service:
<a href="https://i.stack.imgur.com/df275.png" rel="nofollow noreferrer">packet sender log</a></p>
<p>Im not really sure what the reason for this could be, I think it has something to do with the fact that when I get the services it says  on the external ip field. Also, when I try and retrieve the node IP using <code>minikube ip</code> it gives an address, but when the <code>minikube service --url</code> it gives the 127.0.0.1 address. In any case, using either one does not work.</p>

agracia10
<p>it's not working due to a port configuration mismatch.</p>
<p>You deployment container running on the <code>8006</code> but you have exposed the <code>8080</code> and your target port is : <code>--target-port=80</code></p>
<p>so due to this it's not working.</p>
<p>Ideal flow of traffic goes like :</p>
<pre><code>service (node port, cluster IP or any) &gt; Deployment &gt; PODs
</code></pre>
<p>Below sharing the example for deployment and service</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: blog-app-server-instance
  labels:
    app: blog-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: blog-app
  template:
    metadata:
      labels:
        app: blog-app
    spec:
      containers:
      - name: agracia10/debian_bash:latest
        image: blog-app-server
        ports:
        - containerPort: 8006
---
apiVersion: v1
kind: Service
metadata:
  name: blog-app-service
  labels:
    app: blog-app
spec:
  selector:
    app: blog-app
  type: NodePort
  ports:
  - port: 80
    nodePort: 31364
    targetPort: 8006
    protocol: TCP
    name: HTTP
</code></pre>
<p>so things I have changed are <code>image</code> and <code>target port</code>.</p>
<p>Once your Node port service is up and running you will send the request on Port <strong>80</strong> or <strong>31364</strong></p>
<p>i will redirect the request internally to the target port which is <strong>8006</strong> for the container also.</p>
<p>Using this command you exposed your deployment on wrong target point</p>
<pre><code>kubectl expose pod deployment-test-8497d6f458-xxhgm --type=NodePort --port=8080 --target-port=80
</code></pre>
<p>ideally it should be <strong>8006</strong></p>
