Expose two ports, one as ClusterIP and other as NodePort

9/26/2017

I have a pod with two containers. An application and a database. I have two replicas for the pod.

I want to expose the application port to be accessed outside the cluster and I do not want to expose the database port.

But I want to access the database port using DNS to balance the traffic.

I can create two services one as NodePort and expose the applicatin port and other service as ClusterIP to expose the database port.

I could also connect to localhost from the application server as the traffic has been balance before. And only expose the app server as nodeport.

The questions is: Could I expose the database port as cluster ip and the app port as nodeport with only one service?

Thank you.

-- Jxadro
kubernetes

2 Answers

9/26/2017

No. You can't.

Not to mention the fact it is a really rare situation where it makes sense to keep database in the same pod in a replicated setup, as you usually want to separate them into different deployments/services.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

9/26/2017

The answer is: No, you can not.

But you should still know that a Kubernetes Service of type NodePort will also allocate a Cluster IP to which the port will route. So if your wanted to publish both ports, a single Service would be sufficient to reach them internally via the name and externally via node ports.

-- Simon Tesar
Source: StackOverflow