I have a kubernetes cluster with 1 pod and 3 containers inside it. One container is a flask app and it redirects the appropriate request to one of the two other containers based on the request.
The problem is my flask app is only able to access one container. Below is my deployment file:
apiVersion: v1
kind: Service
metadata:
name: flask-service
labels:
run: flask-service
spec:
selector:
app: flask
ports:
- protocol: "TCP"
port: 5000
targetPort: 5000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask
spec:
selector:
matchLabels:
app: flask
replicas: 1
template:
metadata:
labels:
app: flask
spec:
containers:
- name: flask
image: gcr.io/translatefx/flask
ports:
- containerPort: 5000
- name: tagatag-container
image: gcr.io/XXX/tagatag
ports:
- containerPort: 8501
- name: defined-terms-container
image: gcr.io/XXX/defined_terms
ports:
- containerPort: 8501
If my deployment includes both containers (as shown below), only one will work.
- name: tagatag-container
image: gcr.io/XXX/tagatag
ports:
- containerPort: 8501
- name: defined-terms-container
image: gcr.io/XXX/defined_terms
ports:
- containerPort: 8501
What could I possibly be doing wrong?
If you want to run multi-containers in only one Pod.
You should run several containers in a Pod to listen on different ports
image: gcr.io/XXX/tagatag
ports:
- containerPort: 8501
- name: defined-terms-container
image: gcr.io/XXX/defined_terms
ports:
- containerPort: 8502