<p>Hi all i am trying to hit kubernetes service which is running a fastapi app on it and keep getting this connection refused, any insight here would be helpful, thanks in advance</p>
<pre><code>curl -X POST &quot;https://file-monitoring-ms.default.svc.cluster.local:8000/api/v1/filemonitor/&quot; -H  &quot;accept: application/json&quot; -H  &quot;Content-Type: application/json&quot;
-d &quot;{}&quot;
</code></pre>
<p><strong>i also tried file-monitoring-ms.default.svc.cluster.local:8000/api/v1/filemonitor/, as endpoint same connection refused</strong> without the https</p>
<pre><code>app.include_router(filesmonitor, prefix='/api/v1/filemonitor', tags=['filemonitor'])

...

...

@filesmonitor.post(&quot;/&quot;, status_code=201)
async def getSqsEvent
</code></pre>
<pre><code>kind: Deployment
metadata:
  labels:
    app: file-monitoring-ms
  name: file-monitoring-ms
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: file-monitoring-ms
    spec:
      containers:
        - name: file-monitoring-ms
          imagePullPolicy: Never
          image: file-monitoring-image:latest
          ports:
            - containerPort: 8000
              protocol: TCP
  selector:
    matchLabels:
      app: file-monitoring-ms
---
apiVersion: v1
kind: Service
metadata:
  name: file-monitoring-ms
  labels:
    app: file-monitoring-ms
spec:
  selector:
    app: file-monitoring-ms
  ports:
    - name: http
      targetPort: 8000  # port the container accepts traffic on
      port: 8000  # port other pods use to access the Service
      protocol: TCP
</code></pre>
<p>here is the describe on the service
<a href="https://i.stack.imgur.com/tblfh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tblfh.png" alt="enter image description here" /></a></p>
<p>also here is the container saying its running and listening
<a href="https://i.stack.imgur.com/aG3Zt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aG3Zt.png" alt="enter image description here" /></a></p>

dedpo
<p>In Kubernetes, there is types of service</p>
<p>The default one is <strong>Cluster IP</strong> : Which is only accessible internally inside the cluster</p>
<p><strong>Load Balancer</strong> : Expose the service directly and openly to internet using IP.</p>
<p><strong>Node Port</strong>: Using Node or worker node application get exposed to the internet.</p>
<p><strong>For local testing :</strong></p>
<pre><code>kubectl port-forward svc/file-monitoring-ms 8081:8080
</code></pre>
<p>this will create the proxy between CLuster to local port</p>
<p>you can access your API now at :</p>
<pre><code>curl http://localhost:8081
</code></pre>
<p>Your default service type of CLuster IP so service wont be accessible using the <code>curl</code> over the internet</p>
<p>Above command only for development purposes or to debug the things.</p>
<p>Local port <code>8081</code> will direct forward request to service port <code>8080</code> using the kubectl proxy.</p>
<p>Final answer :</p>
<p>If you will run another container in the same cluster and hit this URL it will work however your service is not exposed you won't be able to access the data out of the cluster.</p>
