bootstrapping containers with confd

Post on 12-Feb-2017

2.487 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Bootstrapping containers with

confd

Michael Richardson @m_richo

Who’s heard of

Common methods for configuring containers

Common methods for configuring containers

1.Environment variables2.Data volumes3.External Systems

1. Environment variables

1. Environment variables

docker run -d --hostname my-rabbit \--name some-rabbit \-e RABBITMQ_DEFAULT_USER=user \-e RABBITMQ_DEFAULT_PASS=password \-e RABBITMQ_DEFAULT_VHOST=my_vhost \rabbitmq:3-management

1. Environment variables

docker run -d --hostname my-rabbit \--name some-rabbit \-e RABBITMQ_DEFAULT_USER=user \-e RABBITMQ_DEFAULT_PASS=password \-e RABBITMQ_DEFAULT_VHOST=my_vhost \rabbitmq:3-management

1. Environment variables

• super easy to set

• Most applications are configured by config files rather than env vars.

2. Data volumes

2. Data volumesdocker run -d \--name some-nginx \-v /some/nginx.conf:/etc/nginx/nginx.conf:ro nginx

2. Data volumesdocker run -d \--name some-nginx \-v /some/nginx.conf:/etc/nginx/nginx.conf:ro nginx

2. Data volumes• easily pass any configuration files

from docker host to containers.

• Doesn’t scale too well

3. External Systems

3. External Systems

3. External Systems

• Strong feature list and benefits

• More complexity

What do I want?

What do I want?

Simple method to set config files when

bootstrapping containers

What do I want?

Simple method to set config files when

bootstrapping containers

Say hi to

confd

confdUses templates and data to render local configuration files.

https://github.com/kelseyhightower/confd

confdSource of data• etcd• consul• dynamodb• Redis• Zookeeper• environment variables

confdSource of data• etcd• consul• dynamodb• Redis• Zookeeper• environment variables

Confd exampleconfd Nginx template /etc/confd/templates/nginx.conf.tmpl

server { server_name {{ getenv "proxy_domain" }}; location / { proxy_pass http://{{ getenv "backend_host" }}; proxy_redirect off; }}

Confd exampleconfd Nginx config/etc/confd/conf.d/nginx.conf.toml

[template]src = "proxy.conf.tmpl”dest = "/etc/nginx/conf.d/proxy.conf”

Confd example$ export proxy_domain=mydomain$ export backend_host=www.mricho.com$ /usr/local/bin/confd -onetime -backend env

$ cat /etc/nginx/conf.d/proxy.confserver { server_name mydomain; location / { proxy_pass http://www.mricho.com; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}

Confd example$ export proxy_domain=mydomain$ export backend_host=www.mricho.com$ /usr/local/bin/confd -onetime -backend env

$ cat /etc/nginx/conf.d/proxy.confserver { server_name mydomain; location / { proxy_pass http://www.mricho.com; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}

Confd appied to containers

Confd appied to containers1. Install confd binary to docker images (Dockerfile)2. Add confd templates and config to docker images (Dockerfile)3. Create a bootstrap script for your container at runtime

Confd appied to containers1. Install confd binary to docker images (Dockerfile)2. Add confd templates and config to docker images (Dockerfile)3. Create a bootstrap script for your container at runtime

#!/bin/bashset -e export proxy_domain=${proxy_domain:-$HOSTNAME}test $backend_host

/usr/local/bin/confd -onetime -backend env

echo "Starting Nginx”exec /usr/sbin/nginx -c /etc/nginx/nginx.conf

Confd appied to containers1. Install confd binary to docker images (Dockerfile)2. Add confd templates and config to docker images (Dockerfile)3. Create a bootstrap script for your container at runtime4. Run a container

docker run -it -p 80:80 \-e proxy_domain=mydomain \-e backend_host=www.mricho.com \confd-test

More than ‘strings’

More than ‘strings’upstream backend_hosts {{{ $nodes := split (getenv "app_servers") ":" }}{{range $nodes}} server {{.}};{{end}}}

app_servers="myapp01.local:myapp02.local:myapp03.local:myapp04.local"

upstream backend_hosts { server myapp01.local; server myapp02.local; server myapp03.local; server myapp04.local;}

confd

Configure container config files at runtime

with environment variables

top related