<p>Brand new to kubernetes and am having an issue where I am getting a 502 bad gateway when trying to hit the api.</p>

<p>My configs look like this</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
    name: api-cluster-ip-service
spec:
    type: ClusterIP
    selector:
        component: api
    ports:
        - port: 80
          targetPort: 5000


apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: api
  template:
    metadata:
      labels:
        component: api
    spec:
      containers:
        - name: books-api
          image: mctabor/books-api
          ports:
            - containerPort: 5000


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: books-ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - path: /api/?(.*)
            backend:
              serviceName: api-cluster-ip-service
              servicePort: 80
</code></pre>

<p>and in my flask app I have the following:</p>

<pre><code>if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
</code></pre>

<p>Not sure where I went wrong here</p>

<p>my minikube ip is 192.168.99.104 and I'm trying to hit the api route of 192.168.99.104/api/status</p>

<p>You didn't expose your service properly. First of all, a service of type <em>ClusterIP</em> is only available within the cluster. As you are using minikube, you should try changing the type do <em>NodePort</em>.  </p>

<p>In second place, the <strong>port</strong> declared in the yaml is the port which makes the service visible to other services within the cluster.</p>

<p>After creating the a NodePort Service, execute <code>kubectl get svc</code> to see the external port assigned to the service. You will see something like <em>80:30351/TCP</em>. This means you can access the service at <em>192.168.99.104:30351</em>.</p>

<p><a href="https://stackoverflow.com/a/40774861/8971507">This</a> is a great answer at explaining how to expose a service in minikube</p>
