This is my template:
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi
labels:
app: fastapi
spec:
replicas: 1
selector:
matchLabels:
app: fastapi
template:
metadata:
labels:
app: fastapi
spec:
containers:
- name: fastapi
image: datamastery/fastapi
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: fastapi-service
spec:
selector:
app: fastapi
type: LoadBalancer
ports:
- protocol: TCP
port: 5000
targetPort: 5000
nodePort: 30002
I use a custom fastapi Docker image, which works fine locally. If I understand it correctly, I can expose my Service to the outside world on port 30002.
I run minikube service fastapi-service
and a new Browsertab opens with the following URL: http://192.168.49.2:30002
. Unfortunately nothing is shown. I tried the internal URL (http://127.0.0.1:55202
) which also does not work, as expected. Am I doing here something wrong with Kubernetes or might my app be the issue? Does anyone see something I miss here?
CodePudding user response:
From the my sandbox logs, it seems like its listening on port 3000
INFO: Started server process [1]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:3000 (Press CTRL C to quit)
so change the port from 5000
to 3000
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi
labels:
app: fastapi
spec:
replicas: 1
selector:
matchLabels:
app: fastapi
template:
metadata:
labels:
app: fastapi
spec:
containers:
- name: fastapi
image: datamastery/fastapi
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: fastapi-service
spec:
selector:
app: fastapi
type: LoadBalancer
ports:
- protocol: TCP
port: 5000
targetPort: 3000
nodePort: 30002