<p>I use minikube to deploy example nginx image.<br />
I want to access nginx from localhost ex: <a href="http://127.0.0.1:8080" rel="nofollow noreferrer">http://127.0.0.1:8080</a><br />
I get ERR_CONNECTION_REFUSED</p>
<p><strong>kubectl apply -f nginx.yml</strong><br />
deployment.apps/nginx-deployment-name created</p>
<p><strong>kubectl apply -f nginx-service.yml</strong><br />
service/nginx-service-name created</p>
<p><strong>Deployment</strong> yml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-name
  labels:
    name: nginx-deployment-name-label
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx-template-name
  template:
    metadata:
      labels:
        name: nginx-template-name
    spec:
      containers:
      - name: nginx-container-name
        image: nginx
        ports:
        - containerPort: 8080
</code></pre>
<p><strong>Service</strong> yml</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service-name
spec:
  selector:
    name: nginx-deployment-name-label
  type: NodePort
  ports:
  - name: http
    port: 8080
    targetPort: 8080
    nodePort: 30003
    protocol: TCP
</code></pre>

Metin Bulak
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    name: nginx
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30080
      name: http
  selector:
    name: nginx
</code></pre>
<p>Then if you are on minikube for example:</p>
<pre><code>➜  minikube ip
192.168.49.2

curl http://192.168.49.2:30080/
</code></pre>
