I'm learning Kubernetes over Minikube. My demo consists of a Flask API and a MySQL Database. I made all the .yaml files but something strange happens with services of the deployments...
I cannot communicate with the API externally (neither with Postman, Curl, browser...)
By "externally" I mean "from outside the cluster" (on the same machine, ex: from the browser, postman...)
This the Deployment+Service for the API:
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-dip-api-deployment
labels:
app: api-dip-api
spec:
replicas: 1
selector:
matchLabels:
app: api-dip-api
template:
metadata:
labels:
app: api-dip-api
spec:
containers:
- name: api-dip-api
image: myregistry.com
ports:
- containerPort: 5000
env:
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: api-secret
key: api-db-user
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: api-secret
key: api-db-password
- name: DATABASE_HOST
valueFrom:
configMapKeyRef:
name: api-configmap
key: api-database-url
- name: DATABASE_NAME
valueFrom:
configMapKeyRef:
name: api-configmap
key: api-database-name
- name: DATABASE_PORT
valueFrom:
configMapKeyRef:
name: api-configmap
key: api-database-port
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: Service
metadata:
name: api-service
spec:
selector:
app: api-dip-api
ports:
- port: 5000
protocol: TCP
targetPort: 5000
nodePort: 30000
type: LoadBalancer
Dockerfile API:
FROM python:latest
# create a dir for app
WORKDIR /app
# intall dependecies
COPY requirements.txt .
RUN pip install -r requirements.txt
# source code
COPY /app .
EXPOSE 5000
# run the application
CMD ["python", "main.py"]
Since i'm using Minikube the correct IP for the service is displayed with
minikube service <service_name>
I already tried looking the minikube context, as suggested in another post, but it shows like:
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* minikube minikube minikube default
so it should be ok.
I don't know what to try now... the ports are mapped correctly I think.