Do not create the portainer network. Fix the haproxy configuration

This commit is contained in:
Andrea Dell'Amico 2020-10-01 18:28:54 +02:00
parent 15ae321889
commit 3f73df2bd6
3 changed files with 19 additions and 5 deletions

View File

@ -4,6 +4,7 @@ docker_swarm_cluster_haproxy_install: True
docker_swarm_haproxy_installation_type: 'keepalive' docker_swarm_haproxy_installation_type: 'keepalive'
docker_swarm_haproxy_networks: docker_swarm_haproxy_networks:
- 'portainer_{{ docker_swarm_portainer_network }}' - 'portainer_{{ docker_swarm_portainer_network }}'
docker_swarm_haproxy_additional_networks: []
# #
docker_swarm_expose_api_via_haproxy: True docker_swarm_expose_api_via_haproxy: True
docker_swarm_expose_api_hostname: 'swarm.example.com' docker_swarm_expose_api_hostname: 'swarm.example.com'

View File

@ -1,12 +1,12 @@
--- ---
- name: Create the networks that haproxy will attach to - name: Create the networks that haproxy will attach to and that are not created by the services
block: block:
- name: Create the overlay networks - name: Create the overlay networks that are not created by the services
docker_network: docker_network:
name: '{{ item }}' name: '{{ item }}'
driver: overlay driver: overlay
scope: swarm scope: swarm
with_items: '{{ docker_swarm_haproxy_networks }}' with_items: '{{ docker_swarm_haproxy_additional_networks }}'
# - name: Connect haproxy to the overlay networks # - name: Connect haproxy to the overlay networks
# docker_network: # docker_network:
@ -16,5 +16,13 @@
# appends: yes # appends: yes
# with_items: '{{ docker_swarm_haproxy_networks }}' # with_items: '{{ docker_swarm_haproxy_networks }}'
# - name: Connect haproxy to the overlay additional networks
# docker_network:
# name: '{{ item }}'
# connected:
# - 'haproxy_haproxy'
# appends: yes
# with_items: '{{ docker_swarm_haproxy_additional_networks }}'
when: docker_swarm_manager_main_node | bool when: docker_swarm_manager_main_node | bool
tags: [ 'haproxy', 'docker_haproxy', 'docker_swarm', 'docker', 'docker_network' ] tags: [ 'haproxy', 'docker_haproxy', 'docker_swarm', 'docker', 'docker_network' ]

View File

@ -83,6 +83,7 @@ frontend http
{% if docker_swarm_expose_api_via_haproxy %} {% if docker_swarm_expose_api_via_haproxy %}
acl swarm_api hdr_dom(host) -i {{ docker_swarm_expose_api_hostname }} acl swarm_api hdr_dom(host) -i {{ docker_swarm_expose_api_hostname }}
acl swarm_api_allowed_nets src {% for net in docker_swarm_api_networks_acl %} {{ net }}{% endfor %} acl swarm_api_allowed_nets src {% for net in docker_swarm_api_networks_acl %} {{ net }}{% endfor %}
http-request deny if swarm_api !swarm_api_allowed_nets http-request deny if swarm_api !swarm_api_allowed_nets
use_backend swarm_api_bck if swarm_api use_backend swarm_api_bck if swarm_api
{% endif %} {% endif %}
@ -90,6 +91,7 @@ frontend http
acl {{ srv.acl_name }} {{ srv.acl_rule }} acl {{ srv.acl_name }} {{ srv.acl_rule }}
{% if srv.allowed_networks is defined %} {% if srv.allowed_networks is defined %}
acl {{ srv.acl_name }}_nets src {% for net in srv.allowed_networks %} {{ net }}{% endfor %} acl {{ srv.acl_name }}_nets src {% for net in srv.allowed_networks %} {{ net }}{% endfor %}
http-request deny if {{ srv.acl_name }} !{{ srv.acl_name }}_nets http-request deny if {{ srv.acl_name }} !{{ srv.acl_name }}_nets
{% endif %} {% endif %}
use_backend {{ srv.acl_name }}_bck if {{ srv.acl_name }} use_backend {{ srv.acl_name }}_bck if {{ srv.acl_name }}
@ -108,14 +110,17 @@ backend swarm_api_bck
{% if docker_swarm_cluster_portainer_install %} {% if docker_swarm_cluster_portainer_install %}
backend portainer_bck backend portainer_bck
option httpchk GET / HTTP/1.1\r\nHost:\ localhost option httpchk
http-check send meth HEAD uri / ver HTTP/1.1 hdr Host localhost
http-check expect rstatus (2|3)[0-9][0-9] http-check expect rstatus (2|3)[0-9][0-9]
balance roundrobin balance roundrobin
server-template portainer- 1 portainer:{{ docker_swarm_portainer_http_port }} check resolvers docker init-addr libc,none server-template portainer- 1 portainer:{{ docker_swarm_portainer_http_port }} check resolvers docker init-addr libc,none
{% endif %} {% endif %}
{% for srv in docker_swarm_haproxy_additional_services %} {% for srv in docker_swarm_haproxy_additional_services %}
option httpchk GET / HTTP/1.1\r\nHost:\ localhost backend {{ srv.acl_name }}_bck
option httpchk
http-check send meth HEAD uri / ver HTTP/1.1 hdr Host localhost
http-check expect rstatus (2|3)[0-9][0-9] http-check expect rstatus (2|3)[0-9][0-9]
balance roundrobin balance roundrobin
server-template {{ srv.service_name }}- {{ srv.service_replica_num }} {{ srv.service_name }}:{{ srv.service_port }} check resolvers docker init-addr libc,none server-template {{ srv.service_name }}- {{ srv.service_replica_num }} {{ srv.service_name }}:{{ srv.service_port }} check resolvers docker init-addr libc,none