How to configure multiple services/containers in Kubernetes? How to configure multiple services/containers in Kubernetes? kubernetes kubernetes

How to configure multiple services/containers in Kubernetes?


You are running two containers in the same pod which bind both to port 80. This is not possible within the same pod.Think of a pod like a 'server' and you can't have two processes bind to the same port.

Solution in your situation: Use different ports inside the pod or use separate pods. From your deployment there seems to be no shared resources like filesystem, so it would be easy to split the containers to separate pods.

Note that it will not suffice to change the pod definition if you want to have both containers running in the same pod with different ports. The application in the container must bind to a different port as well.


apiVersion: v1kind: Podmetadata:  name: two-containersspec:  restartPolicy: Never  volumes:  - name: shared-data    emptyDir: {}  containers:  - name: nginx-container    image: nginx    volumeMounts:    - name: shared-data      mountPath: /usr/share/nginx/html  - name: debian-container    image: debian    volumeMounts:    - name: shared-data      mountPath: /pod-data    command: ["/bin/sh"]    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"] 

here sharing example for multi container you can use this template

Also you can check for logs of using

Kubectl logs

Check reason for crashloop back