Skip to content

Commit

Permalink
Install skydns and skydock
Browse files Browse the repository at this point in the history
* Skydns servers are configured in a cluster. This requires a new
`dns_leader` Ansible variable.

* Skydock is run on each server and talks to the master skydns (it
should talk to the local one, but a bug in the skydns code prevents it,
see comments)
* Some updates to the README
  • Loading branch information
amuino committed Feb 11, 2014
1 parent 2370000 commit e226b0b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ WIP for managing a collection of docker hosts

```
host1 ansible_ssh_port=2251 host_id=1 other_hosts="192.168.50.102 192.168.50.103"
host2 ansible_ssh_port=2252 host_id=2 other_hosts="192.168.50.101"
host3 ansible_ssh_port=2253 host_id=3 other_hosts="192.168.50.101"
host2 ansible_ssh_port=2252 host_id=2 other_hosts="192.168.50.101" dns_leader=10.10.1.1
host3 ansible_ssh_port=2253 host_id=3 other_hosts="192.168.50.101" dns_leader=10.10.1.1
```

##Configure the servers as docker's hosts
Expand All @@ -38,8 +38,8 @@ ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --user=vagrant --private-key=~/

```
public_ip_address_host_1 host_id=1 other_hosts="private_ip_address_host_2 private_ip_address_host_3"
public_ip_address_host_2 host_id=2 other_hosts="private_ip_address_host_1"
public_ip_address_host_3 host_id=3 other_hosts="private_ip_address_host_1"
public_ip_address_host_2 host_id=2 other_hosts="private_ip_address_host_1" dns_leader=10.10.1.1
public_ip_address_host_3 host_id=3 other_hosts="private_ip_address_host_1" dns_leader=10.10.1.1
```

##Prepare the servers
Expand All @@ -54,10 +54,11 @@ ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --inventory-file=docker_hosts a
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --user=ubuntu --inventory-file=docker_hosts ansible-playbooks/docker.yml
```

##Notes
#Notes

* The host 1 will act as *network concentrator*, all traffic will pass through it.
* The docker service will be available in IP address 10.10.X.1, X is the `host_id`
* The containers in host X will have an IP address like 10.10.X.Y, X is the `host_id`
* The `dns_leader` parameter must point point to the ip of the docker bridge

**ENJOY!**
92 changes: 92 additions & 0 deletions ansible-playbooks/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,99 @@
apt_repository: repo='deb http://get.docker.io/ubuntu docker main' state=present
tags: docker repo

- name: Create the docker group
user: name=docker state=present

- name: Add ansible user to the docker group
user: name={{ ansible_ssh_user }} groups=docker append=true

- name: Install docker
apt: pkg=lxc-docker state=present update_cache=yes cache_valid_time=14400
tags: docker repo

- name: Refresh facts to learn about the new network interfaces
setup: ''

- name: Reconfigure docker
lineinfile: >
dest=/etc/init/docker.conf
state=present
regexp='( *DOCKER_OPTS=).*'
line='\1"--dns {{ facter_ipaddress_docker0 }}"'
backrefs=yes
- name: Apply docker configuration
shell: stop docker ; start docker

- name: Pull Skydns
command: docker pull crosbymichael/skydns

- name: Pull Skydock
command: docker pull crosbymichael/skydock

- name: Install skydns master
command: >
docker run -d
-p {{ facter_ipaddress_docker0 }}:53:53/udp
-p {{ facter_ipaddress_docker0 }}:8080:8080/tcp
-name skydns
--entrypoint /bin/bash
crosbymichael/skydns
-c 'skydns -http $(hostname -i):8080 -dns $(hostname -i):53 -nameserver 8.8.8.8:53 -domain docker'
when: dns_leader is not defined

- name: Wait for master
wait_for: host={{ facter_ipaddress_docker0 }} port=8080 timeout=30
when: dns_leader is not defined

- name: Install skydock on master
command: >
docker run -d -v /var/run/docker.sock:/docker.sock
-name skydock
-link skydns:skydns
crosbymichael/skydock
-ttl 30
-s /docker.sock
-environment dev
-domain docker
when: dns_leader is not defined

- name: Install skydns on slaves
command: >
docker run -d -p {{ facter_ipaddress_docker0 }}:53:53/udp
-name skydns
--dns {{ dns_leader }}
--entrypoint bash
crosbymichael/skydns
-c 'skydns -http $(hostname -i):8080 -dns $(hostname -i):53 -nameserver 8.8.8.8:53 -domain docker -join master.docker:8080'
when: dns_leader is defined

- name: Install skydock on slaves
#
# BUG: This should work, but the skydns api client does not handle the redirection to the master
# See: https://github.com/skynetservices/skydns/pull/79
#
# command: >
# docker run -d -v /var/run/docker.sock:/docker.sock
# -name skydock
# -link skydns:skydns
# crosbymichael/skydock
# -ttl 30
# -s /docker.sock
# -environment dev
# -domain docker

#
# WORKAROUND: Set the skydnsUrl to the master. I guess this can break if a new master is elected
command: >
docker run -d -v /var/run/docker.sock:/docker.sock
-name skydock
crosbymichael/skydock
--skydns http://master.docker:8080
-ttl 30
-s /docker.sock
-environment dev
-domain docker
when: dns_leader is defined


0 comments on commit e226b0b

Please sign in to comment.