Add HAProxy and Consul template to mesos slaves for internal service discovery
This commit is contained in:
Родитель
03b19d93a3
Коммит
8924f489ee
|
@ -0,0 +1,36 @@
|
|||
global
|
||||
log /dev/log local0
|
||||
log /dev/log local1 notice
|
||||
chroot /var/lib/haproxy
|
||||
maxconn 4000
|
||||
stats socket /run/haproxy/admin.sock mode 660 level admin
|
||||
stats timeout 30s
|
||||
user haproxy
|
||||
group haproxy
|
||||
daemon
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode tcp
|
||||
timeout connect 5000
|
||||
timeout client 500000
|
||||
timeout server 500000
|
||||
|
||||
{{- $aws_env := env "AWS_ENV" }}
|
||||
{{ range services -}}
|
||||
{{- if .Tags.Contains $aws_env }}
|
||||
{{- $service_port_key := (print "services/" .Name "/" $aws_env "/port") -}}
|
||||
{{- $service_port := (key_or_default $service_port_key "") -}}
|
||||
{{- if $service_port }}
|
||||
listen {{ .Name }}
|
||||
bind 0.0.0.0:{{ $service_port }}
|
||||
mode tcp
|
||||
option clitcpka
|
||||
balance roundrobin
|
||||
{{- $env_services := (print $aws_env "." .Name) }}
|
||||
{{ range service $env_services }}
|
||||
server {{.ID}} {{ .NodeAddress }}:{{ .Port }} check
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -18,3 +18,8 @@
|
|||
name: consul
|
||||
enabled: yes
|
||||
state: restarted
|
||||
|
||||
- name: restart consul-template
|
||||
service:
|
||||
name: consul-template
|
||||
state: restarted
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
|
||||
dependencies:
|
||||
- { role: consul-template }
|
|
@ -79,3 +79,19 @@
|
|||
state: present
|
||||
tags:
|
||||
- mesos
|
||||
|
||||
- name: Enable haproxy ppa
|
||||
apt_repository:
|
||||
repo: "ppa:vbernat/haproxy-1.6"
|
||||
state: present
|
||||
tags:
|
||||
- haproxy
|
||||
- consul-template
|
||||
|
||||
- name: Install haproxy
|
||||
apt:
|
||||
name: "haproxy"
|
||||
state: present
|
||||
tags:
|
||||
- haproxy
|
||||
- consul-template
|
||||
|
|
|
@ -104,6 +104,39 @@
|
|||
tags:
|
||||
- docker
|
||||
|
||||
- name: Make sure haproxy folder exists
|
||||
file:
|
||||
path: /var/run/haproxy
|
||||
state: directory
|
||||
tags:
|
||||
- haproxy
|
||||
|
||||
- name: Add consul-template configuration
|
||||
template:
|
||||
src: consul_template_config.j2
|
||||
dest: /etc/consul-template.d/config
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify:
|
||||
- restart consul-template
|
||||
tags:
|
||||
- haproxy
|
||||
- consul-template
|
||||
|
||||
- name: Add haproxy config template
|
||||
copy:
|
||||
src: haproxy.ctmpl
|
||||
dest: /etc/consul-template.d/templates/haproxy.ctmpl
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify:
|
||||
- restart consul-template
|
||||
tags:
|
||||
- haproxy
|
||||
- consul-template
|
||||
|
||||
- name: Setup consul service and check definitions
|
||||
template:
|
||||
src: consul.json.j2
|
||||
|
@ -115,3 +148,4 @@
|
|||
- restart consul
|
||||
tags:
|
||||
- consul
|
||||
- haproxy
|
||||
|
|
|
@ -15,5 +15,12 @@
|
|||
"timeout": "4s"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "haproxy-internal",
|
||||
"id": "haproxy-internal-{{ ec2_id }}",
|
||||
"tags": ["haproxy-internal", "{{ ec2_tag_env }}"],
|
||||
"port": 1936,
|
||||
"enableTagOverride": false
|
||||
}
|
||||
]}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
consul = "{{ ansible_default_ipv4['address'] }}:8500"
|
||||
|
||||
template {
|
||||
source = "/etc/consul-template.d/templates/haproxy.ctmpl"
|
||||
destination = "/etc/haproxy/haproxy.cfg"
|
||||
command = "service haproxy restart"
|
||||
}
|
Загрузка…
Ссылка в новой задаче