2 ports for 1 Ingres / services / statefulsets/ pods

3/31/2019

Requirement : I have two docker containers where both expose to different ports. (For eg port 9001 and 9002)

From the requirement, I try to design the kubernetes objects and their relationships but I am unsure whether A or B is correct.

A) 1 Ingres connect to 1 service. And 1 service connect to 1 statefulset with 1 pod of 2 containers

B) 2 Ingres connect to 2 services. And 2 service connect to 2 statefulset with 2 pod. Every pod have 1 container.

I want to ask the following questions:

  1. Can 1 Ingres or 1 service or 1 statefulset or 1 pod serves 2 ports? If can then probably A is correct, else B is correct.
  2. Also base on my question, can anyone tell me whether my understanding of kubernetes is correct or wrong?
-- Charles Brown
devops
docker
kubernetes
networking

3 Answers

3/31/2019

1 ingress can serve n number of services and routes external connections to services based on the host and hostPath.

1 service can serve multiple ports and it assigns different nodeports mapping to each port.

1 pod can aslo serve multiple ports and it depends on the port you expose in your manifest.

Statefulsets are more like pods manifest it’s just that they provide a addon functionality of persistence of volumes.

-- Aman Juneja
Source: StackOverflow

3/31/2019

From what I understood, you only need 1 stateful app, the other one can be stateless and persist data in the first app. If you are following the microsservices paradigm you should separate your apps in stateless and stateful services.
It's also important to note that unless two containers are tightly coupled they shouldn't be on the same pod. The separations allows a more flexible scalability, as you don't need to have the same number of replicas of both containers.
In conclusion, I would do the following:

  • Create a Deployment containing only the image of your stateless app.
  • Create a StatefulSet for the stateful app.
  • Create 2 services, one for each app.
  • Create 1 ingress for your stateless app.

The ingress will allow routing from request coming from outside the cluster to your app's service. Even if yout statefull app doesn't communicate with the external world, creationg a service for him will allow easier communication between the apps inside the cluster (you can use a fixed IP or even DNS)

-- victortv
Source: StackOverflow

3/31/2019

You can run two containers on the same pod, The Java can run on port 8080 And the Eheterum can run on port 3306.

Then you can use localhost:8080 from within the container to reach the Java, and the java can reach the etherum on localhost:3306.

If no access from outside the cluster is required Ingress is not required.

Hope that it answers your question.

-- Shai Katz
Source: StackOverflow