<p>I have a very simple Python app that works fine when I execute <code>uvicorn main:app --reload</code>. When I go to <code>http://127.0.0.1:8000</code> on my machine, I'm able to interact with the API. (My app has no frontend, it is just an API built with FastAPI). However, I am trying to deploy this via Kubernetes, but am not sure how I can access/interact with my API.</p>
<p>Here is my <code>deployment.yaml</code>.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec: 
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16.1
        ports:
        - containerPort: 80
</code></pre>
<p>When I enter <code>kubectl describe deployments my-deployment</code> in the terminal, I get back a print out of the deployment, the namespace it is in, the pod template, a list of events, etc. So, I am pretty sure it is properly deployed.</p>
<p>How can I access the application? What would the url be? I have tried a variety of localhost  + port combinations to no avail. I am new to kubernetes so I'm trying to understand how this works.</p>
<hr />
<p><strong><strong>Update:</strong></strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deployment
  namespace: default  
spec:  
  selector: 
    matchLabels:
      app: web
  replicas: 2  
  template:  
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: site
        image: nginx:1.16.1
        ports:
          - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: app-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30001

</code></pre>
<p>Again, when I use the k8s CLI, I'm able to see my deployment, yet when I hit <code>localhost:30001</code>, I get an <code>Unable to connect</code> message.</p>

TheRealFakeNews
<p>You have given <code>containerPort: 80</code> but if your app listens on port <code>8080</code> change it to <code>8080</code>.</p>
<p>There are different ways to access an application deployed on kubernetes</p>
<ol>
<li><a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">Port Forward</a> using <code>kubectl port-forward deployment/my-deployment 8080:8080</code></li>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">Creare a NodePort service</a> and use <code>http://&lt;NODEIP&gt;:&lt;NODEPORT&gt;</code></li>
<li><a href="https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/" rel="nofollow noreferrer">Create a LoadBalanceer service</a>. This works only in supported cloud environment such as AWS, GKE etc.</li>
<li><a href="https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/" rel="nofollow noreferrer">Use ingress controller</a> such nginx to expose the application.</li>
</ol>
