<p>I'm new to k8 and i'm trying to figure out how to deploy my first docker image on minikube.</p>
<p>My k8.yaml file is:</p>
<pre><code>apiVersion: apps/v1

kind: Deployment

metadata:
  name: my-deployment
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-docker-image
        image: my-docker-image:1.0
        ports:
         - containerPort: 8080


---
apiVersion: v1

kind: Service

metadata:
  name: my-service
  namespace: default
spec:
  type: LoadBalancer
  selector:
    app: my-service
  ports:
    - port: 8080
      targetPort: 8080
    
     
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: my-ingress
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 8080
</code></pre>
<p>Everything seems fine to me, however, I'm not able to reach my service on cluster.
I tried to create a tunnel using the <code>minikube tunnel</code> command and i have this result if i execute <code>kubectl get services</code></p>
<pre><code>NAME        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
my-service  LoadBalancer   10.109.154.236   127.0.0.1     8080:30558/TCP   2m53s
</code></pre>
<p>However, if i try to call my service at 127.0.0.1:30588 host is unreachable.</p>
<p>Can someone help me?</p>

Luca Farsetti
<p>There is an issue in the service selector as well, so first, we need to fix this service selector and it should match with with deployment label</p>
<pre><code>  replicas: 1
  selector:
    matchLabels:
      app: my-app
</code></pre>
<p>and the service should refer to this <code>selector</code></p>
<p>the selector should be <code>my-app</code> in the service or same as above for deployment</p>
<pre><code>  type: LoadBalancer
  selector:
    app: my-app
  ports:
    - port: 8080
      targetPort: 8080
</code></pre>
<p>to access from the host</p>
<pre><code>minikube service my-service
</code></pre>
<p><a href="https://i.stack.imgur.com/4Kjj0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Kjj0.png" alt="enter image description here" /></a></p>
<p>and here you go</p>
<pre><code>kubectl delete -f myapp.yaml
kubectl apply -f myapp.yaml
</code></pre>
<p>deployment manifest</p>
<pre><code>apiVersion: apps/v1

kind: Deployment
metadata:
  name: my-deployment
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-docker-image
        image: nginx
        ports:
         - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: default
spec:
  type: LoadBalancer
  selector:
    app:  my-app
  ports:
    - port: 80
      targetPort: 80

</code></pre>
<p>Also worth considering the service type for Minikube.</p>
<p><a href="https://stackoverflow.com/questions/41509439/whats-the-difference-between-clusterip-nodeport-and-loadbalancer-service-types">What&#39;s the difference between ClusterIP, NodePort and LoadBalancer service types in Kubernetes?</a></p>
