I'm having an issue where because an application was originally configured to execute on docker-compose. I managed to port and rewrite the .yaml deployment files to Kubernetes, however, the issue lies within the communication of the pods.
The frontend communicates with the backend to access the services, and I assume as it should be in the same network, the frontend calls the services from the localhost. I don't have access to the code, as it is an proprietary application that was developed by a company and it does not support Kubernetes, so modifying the code is out of question.
I believe the main reason is because the frontend and backend are runnning on different pods, with different IPs.
When the frontend tries to call the APIs, it does not find the service, and returns an error. Therefore, I'm trying to deploy both the frontend image and backend image into the same pod, so they share the same Cluster IP.
Unfortunately, I do not know how to make a yaml file to create both containers within a single pod.
Is it possible to have both frontend and backend containers running on the same pod, or would there be another way to make the containers communicate (maybe a proxy)?
Can we have a single container with multiple image like nginx + Redis + alpine ? You can have multiple processes inside a container but it wouldn't really be a best practice. Having NGINX and Redis in separate containers but inside the same pod would be better.
Creating a pod. Multi-container pods must be created with the create command. Properties are passed to the command as a YAML- or JSON-formatted configuration file. The create command can be used to create a pod directly, or it can create a pod or pods through a Deployment .
At the same time, a Pod can contain more than one container, usually because these containers are relatively tightly coupled.
A Deployment is meant to represent a single group of PODs fulfilling a single purpose together. You can have many Deployments work together in the virtual network of the cluster. For accessing a Deployment that may consist of many PODs running on different nodes you have to create a Service.
As with every file definition in Kubernetes, we define our multi-container pod in a YAML file. So, the first step is to create a new file with the command: In the above YAML file, you will see that we have deployed a container based on the Nginx image, as our web server.
Deploy Docker Image to Kubernetes Quickly with – Kubectl run command ( Deprecated) You make the choice. In this step, we are instantiating our Docker Image as Container. As you know the basic and the core element of Kubernetes is POD and that’s a logical group of one or more containers.
When you first create a Deployment , StatefulSet, Pod, or other object that includes a Pod template, then by default the pull policy of all containers in that pod will be set to IfNotPresent if it is not explicitly specified. This policy causes the kubelet to skip pulling an image if it already exists.
The status ImagePullBackOff means that a container could not start because Kubernetes could not pull a container image (for reasons such as invalid image name, or pulling from a private registry without imagePullSecret ). The BackOff part indicates that Kubernetes will keep trying to pull the image, with an increasing back-off delay.
Therefore, I'm trying to deploy both the frontend image and backend image into the same pod, so they share the same Cluster IP.
Although you have the accepted answer already in place that is tackling example of running more containers in the same pod I'd like to point out few details:
Containers should be in the same pod only if they scale together (not if you want to communicate over clusterIP amongst them). Your scenario of frontend/backend division doesn't really look like good candidate to cram them together.
If you opt for containers to be in the same pod they can communicate over localhost (they see each other as if two processes are running on the same host (except the part their file systems are different) and can use localhost for direct communication and because of that can't allocate both the same port. Using cluster IP is as if on same host two processes are communicating over external ip).
More kubernetes philosophy approach here would be to:
Some of the benefits of this approach include: you can isolate backend better (backend-frontend communication is within cluster only, not exposed to outside world), you can schedule them independently on nodes, you can scale them independently (say you need more backend power but fronted is handling traffic ok or viceversa), you can replace any of them independently etc...
Yes, you just add entries to the containers
section in your yaml file, example:
apiVersion: v1
kind: Pod
metadata:
name: two-containers
spec:
restartPolicy: Never
containers:
- name: nginx-container
image: nginx
- name: debian-container
image: debian
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With