echan00
echan00

Reputation: 2807

Kubernetes flask app w/ multiple containers

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?

Upvotes: 0

Views: 368

Answers (1)

Thanh Nguyen Van
Thanh Nguyen Van

Reputation: 11772

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

Upvotes: 1

Related Questions