diff --git a/swarm-consul-openstack/README.md b/swarm-consul-openstack/README.md new file mode 100644 index 0000000..570f4ee --- /dev/null +++ b/swarm-consul-openstack/README.md @@ -0,0 +1,23 @@ +# Running a Docker Swarm Cluster on OpenStack + +This repository contains files intended to help users run their own Consul-backed Docker Swarm cluster on OpenStack. This solution leverages Docker, Docker Swarm, Consul, CoreOS, and OpenStack (including OpenStack Heat and the Docker plugin for Heat). _A functional OpenStack installation is required to use these files._ + +**WARNING:** These files are not yet fully functional! + +## Contents + +* **consul-cluster.yml**: An OpenStack Heat template to spin up a cluster of Ubuntu 14.04 instances that will run Consul. You'll need to edit this file to provide correct values for an Ubuntu 14.04 image in Glance, the Neutron network to which the instances should be attached, and the Neutron security group that should be applied to these instances. All these values can be obtained using the `glance` and `neutron` CLI clients. + +* **coreos-cluster.yml**: An OpenStack Heat template to spin up a cluster of CoreOS instances running etcd. You'll need to edit this file to provide the values for the correct CoreOS image in Glance, the Neutron security group to be applied to the Neutron ports, and the Neutron network to which to connect these ports (and therefore the instances). All these values are easily obtained using the `neutron` and `glance` CLI clients. + +* **docker-swarm.yml**: An OpenStack Heat template that deploys the necessary Docker Swarm containers onto already-deployed CoreOS instances that are running etcd. You'll need to edit this file to supply the IP addresses of the CoreOS instances. + +* **README.md**: The file you're reading right now. + +## Instructions + +[NOT YET FUNCTIONAL] + +## License + +This material is licensed under the MIT License. diff --git a/swarm-consul-openstack/consul-cluster.yml b/swarm-consul-openstack/consul-cluster.yml new file mode 100644 index 0000000..3d34a5c --- /dev/null +++ b/swarm-consul-openstack/consul-cluster.yml @@ -0,0 +1,68 @@ +heat_template_version: 2013-05-23 +description: > + A simple Heat template to deploy Ubuntu 14.04 instances for Consul. +parameters: + network_id: + type: string + label: Network ID + description: ID of existing Neutron network to use ("infra-net") + default: fd14ddbd-4720-400d-9811-0be84e71f153 + image_id: + type: string + label: Glance Image ID + description: ID of existing Glance image to use ("Ubuntu 14.04 LTS") + default: 6a71dffa-a369-42f5-b3c1-c0bd67bf0c20 + secgroup_id: + type: string + label: Security group ID + description: ID of existing security group ("all") + default: b6499308-f409-401a-a170-c887b10cf5f2 +resources: + consul-01_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + consul-02_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + consul-03_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + consul-01: + type: OS::Nova::Server + properties: + name: consul-01 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: consul-01_port0 } + key_name: lab + consul-02: + type: OS::Nova::Server + properties: + name: consul-02 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: consul-02_port0 } + key_name: lab + consul-03: + type: OS::Nova::Server + properties: + name: consul-03 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: consul-03_port0 } + key_name: lab diff --git a/swarm-consul-openstack/consul-software-config.yml b/swarm-consul-openstack/consul-software-config.yml new file mode 100644 index 0000000..01098bc --- /dev/null +++ b/swarm-consul-openstack/consul-software-config.yml @@ -0,0 +1,50 @@ +consul_config: + type: OS::Heat::SoftwareConfig + properties: + group: script + config: | + #!/bin/bash -ex + apt-get update + apt-get -y install unzip + wget https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip + unzip 0.5.0_linux_amd64.zip + rm 0.5.0_linux_amd64.zip + mv consul /usr/local/bin/ + mv consul.conf /etc/init/ + mkdir /var/consul + useradd -M -d /var/consul -r -s /usr/bin/nologin consul + chown -R consul:consul /var/consul + mkdir -p /etc/consul.d/server + cat > /etc/consul.d/server/config.json < /etc/init/consul.conf <>/var/log/consul.log 2>&1 + end script + EOF diff --git a/swarm-consul-openstack/coreos-cluster.yml b/swarm-consul-openstack/coreos-cluster.yml new file mode 100644 index 0000000..ee0a386 --- /dev/null +++ b/swarm-consul-openstack/coreos-cluster.yml @@ -0,0 +1,143 @@ +heat_template_version: 2013-05-23 +description: > + A simple Heat template to deploy a new CoreOS cluster. +parameters: + network_id: + type: string + label: Network ID + description: ID of existing Neutron network to use ("infra-net") + default: e6da808c-f832-4a70-81a7-8c090824e494 + image_id: + type: string + label: Glance Image ID + description: ID of existing Glance image to use ("CoreOS 522.6.0 Stable") + default: f9cc4dfc-2864-4ddb-a27c-3095d1dd0e09 + secgroup_id: + type: string + label: Security group ID + description: ID of existing security group ("all") + default: 74518432-12ba-4bdb-8d22-09c616b158b0 +resources: + coreos_init: + type: OS::Heat::CloudConfig + properties: + cloud_config: + coreos: + etcd: + discovery: https://discovery.etcd.io/bf3853e90678038d4f6e26d3788729d1 + addr: $private_ipv4:4001 + peer-addr: $private_ipv4:7001 + units: + - name: etcd.service + command: start + - name: fleet.service + command: start + - name: docker-tcp.socket + command: start + enable: true + content: | + [Unit] + Description=Docker Socket for the API + + [Socket] + ListenStream=2375 + BindIPv6Only=both + Service=docker.service + + [Install] + WantedBy=sockets.target + instance0_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + instance1_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + instance2_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + instance3_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + instance4_port0: + type: OS::Neutron::Port + properties: + admin_state_up: true + network_id: { get_param: network_id } + security_groups: + - { get_param: secgroup_id } + instance0: + type: OS::Nova::Server + properties: + name: coreos-node-01 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: instance0_port0 } + key_name: lab + user_data_format: RAW + user_data: + get_resource: coreos_init + instance1: + type: OS::Nova::Server + properties: + name: coreos-node-02 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: instance1_port0 } + key_name: lab + user_data_format: RAW + user_data: + get_resource: coreos_init + instance2: + type: OS::Nova::Server + properties: + name: coreos-node-03 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: instance2_port0 } + key_name: lab + user_data_format: RAW + user_data: + get_resource: coreos_init + instance3: + type: OS::Nova::Server + properties: + name: coreos-node-04 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: instance3_port0 } + key_name: lab + user_data_format: RAW + user_data: + get_resource: coreos_init + instance4: + type: OS::Nova::Server + properties: + name: coreos-node-05 + image: { get_param: image_id } + flavor: m1.small + networks: + - port: { get_resource: instance4_port0 } + key_name: lab + user_data_format: RAW + user_data: + get_resource: coreos_init diff --git a/swarm-consul-openstack/docker-swarm.yml b/swarm-consul-openstack/docker-swarm.yml new file mode 100644 index 0000000..51ba56c --- /dev/null +++ b/swarm-consul-openstack/docker-swarm.yml @@ -0,0 +1,18 @@ +heat_template_version: 2013-05-23 +description: > + Heat template to deploy Docker containers to an existing host +parameters: + node-01: + type: string + label: First node IP address + description: IP address assigned to first Docker Swarm node + default: 172.16.6.21 +resources: + swarm-coreos-01: + type: DockerInc::Docker::Container + properties: + image: swarm + hostname: coreos-01 + name: swarm-coreos-01 + docker_endpoint: "tcp://172.16.6.21:2375" + cmd: [ 'join', '--addr=172.16.6.21:2375', 'etcd://172.16.6.21:4001/swarm-test'] diff --git a/swarm-consul-openstack/docker-workloads.yml b/swarm-consul-openstack/docker-workloads.yml new file mode 100644 index 0000000..e004df2 --- /dev/null +++ b/swarm-consul-openstack/docker-workloads.yml @@ -0,0 +1,24 @@ +heat_template_version: 2013-05-23 +description: > + Heat template to deploy Docker containers to an existing Docker Swarm cluster +parameters: + swarm_endpoint: + type: string + label: First node IP address + description: IP address assigned to first Docker Swarm node + default: tcp://172.16.6.21:8333 +resources: + nginx-01: + type: DockerInc::Docker::Container + properties: + image: nginx + docker_endpoint: { get_param: swarm_endpoint } + port_bindings: + 80: 80 + nginx-02: + type: DockerInc::Docker::Container + properties: + image: nginx + docker_endpoint: { get_param: swarm_endpoint } + port_bindings: + 80: 80