Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes configuration to link containers

I am trying to see if there are any example to create a Kubernetes POD which starts 2-3 containers and these containers are linked with each other but couldn't find any.

Does anybody tried linking containers using Kubernetes config.

like image 655
Ashish Jain Avatar asked Nov 24 '14 11:11

Ashish Jain


People also ask

Can 2 pods communicate in Kubernetes?

Kubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Kubernetes gives every pod its own cluster-private IP address, so you do not need to explicitly create links between pods or map container ports to host ports.


2 Answers

The containers in same pod shares the localhost, so you need not link containers, just use localhost:containerPort.

like image 73
Tony Dun Avatar answered Sep 28 '22 04:09

Tony Dun


You have to use the Kubernetes service (Proxy) https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md#how-do-they-work.

Have a look how they work togehter: https://github.com/GoogleCloudPlatform/kubernetes/tree/master/examples/guestbook

To be specific, there is no concept of "linking" similarly to the way Docker does it. Every service endpoint is a fully qualified domain name and you just call it from one container to another, and every label on a container that can be picked up by a service endpoint can be used to direct network traffic. So, you don't have to do ENV["$FOO_BAR_BAZ"] to get the correct IP, just call it directly (curl http://foo_bar_baz).

like image 42
joh.scheuer Avatar answered Sep 28 '22 05:09

joh.scheuer