kubernetes volumes and sockets

10/18/2017

I have two containers inside the same pod. One is an haproxy container and I'm pushing the haproxy statistics to a socket inside the container. I want to access the socket inside the haproxy container from the other container. I tried to use volume type mkdir but an error occurred mentioning that there is no unix sockets under the directory which I'm trying to access. I'm new to these technologies and please help me to solve this problem.

The yaml file is as follows.

yaml file

-- Saarrah Isthikar
docker-volume
kubernetes

1 Answer

10/19/2017

In reference to kubernetes documentation :

Every container in a Pod shares the network namespace, including the IP address and network ports.

You don't need to use a volume to access to haproxy statistics, just use 127.0.0.1 and the port where the process for haproxy statistics is bound.

Here is an example of a telegraph configuration container deployed in the same pod of an haproxy :

# Telegraf Configuration

[global_tags]
  env = "$ENV"
  tenant = "$TENANT"

[agent]
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_jitter = "5s"
  precision = ""
  debug = false
  quiet = false
  logfile = ""
  hostname = ""
  omit_hostname = false

[[outputs.influxdb]]

 urls = ["http://influxdb.host:2001"]
 database = "db_name"
 retention_policy = ""
 write_consistency = "any"
 timeout = "5s"

[[inputs.haproxy]]

 servers = [ "http://$STATS_USERNAME:$STATS_PASSWORD@127.0.0.1:$STATS_PORT/haproxy?stats" ]

Input use haproxy plugin, output use influxdb. $STATS_USERNAME $STATS_PASSWORDand $STATS_PORTare environment variable shared between 2 containers.

-- Nicolas Pepinster
Source: StackOverflow