Access to other container containers in Kubernet

When I define several containers in the pod / pod template, for example, one container with nginx and another php-fpm, how can they access each other?

Should I define some links in the definition (I could not find documents explaining all the available configuration options) or can they have a different default?

If so, what values ​​should I add to the configuration files? I read the division of the network namespace, but I do not know what this really means?

I also could not find any example for this.

+7
docker kubernetes
source share
2 answers

All containers in the module are bound to the same namespace.

This means that (a) they all have the same IP address and (b) that localhost same in all containers. In other words, if you use Apache in one container in pod and MysQL working in another, you can access MySQL in localhost:3306 from the Apache container (and you can access Apache in localhost:80 from the MySQL container).

As long as the containers share the network, they do not share file systems. If you want to share files between containers, you will need to use volumes. Here is a simple example.

+18
source share

Containers inside the module can communicate with each other using localhost: port_no. .if the nodejs server accesses mongodb and both work in the same module, then just write localhost: 27017 in the connection string. An example of a typical nodejs-mongodb connection inside a module

  var MongoClient = require('mongodb').MongoClient; var url = "mongodb://localhost:27017/mydb"; MongoClient.connect(url, function(err, db) { if (err) throw err; console.log("Database created!"); db.close(); }); 
0
source share

All Articles