Skip to content

Commit 0d6cb4a

Browse files
committed
Implement coredns service discovery
1 parent 74cabf0 commit 0d6cb4a

28 files changed

Lines changed: 315 additions & 29 deletions

File tree

group_vars/all.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ varnish_manager_ssh_key_filename: varnish/sesame
14851485

14861486
# Is varnish hosted on a separate, dedicated node?
14871487
varnish_standalone: yes
1488-
1488+
varnish_lambda_backends_update: "{{ varnish_standalone and not mageops_coredns_enabled }}"
14891489
# Shall standalone varnish instance be used as a loadbalancer (instead of AWS ELB)?
14901490
varnish_as_loadbalancer: "{{ varnish_standalone and mageops_https_termination_enable }}"
14911491

@@ -1825,3 +1825,13 @@ mageops_magento_vary_sign_enabled: no
18251825
mageops_magento_vary_sign_secret: ""
18261826
magento_vary_sign: "{{ mageops_magento_vary_sign_enabled }}"
18271827
magento_vary_secret: "{{ mageops_magento_vary_sign_secret }}"
1828+
1829+
# ---------------------------
1830+
# -------- CoreDNS --------
1831+
# ---------------------------
1832+
mageops_coredns_enabled: no
1833+
mageops_coredns_dynamic_http_port: 2673
1834+
# Required to be set
1835+
# mageops_coredns_dynamic_secret:
1836+
mageops_dynamic_node_enabled: "{{ mageops_coredns_enabled }}"
1837+
varnish_dns_service_discovery: "{{ mageops_dynamic_node_enabled }}"

roles/cs.aws-security-group/tasks/main.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
- proto: tcp
4141
ports: ["{{ goaccess_vhost_port }}"]
4242
cidr_ip: "{{ mageops_trusted_cidr_blocks }}"
43+
- proto: tcp
44+
ports: [ "{{ mageops_coredns_dynamic_http_port }}" ]
45+
group_name: "{{ aws_security_group_app_name }}"
4346
vpc_id: "{{ aws_vpc_id }}"
4447
tags: "{{ aws_tags_default | combine(ec2_sg_tags) }}"
4548
vars:
@@ -214,7 +217,3 @@
214217
vars:
215218
ec2_sg_tags:
216219
Name: "{{ aws_security_group_varnish_name }}"
217-
218-
219-
220-

roles/cs.coredns/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coredns_dynamic_enabled: no
2+
coredns_dynamic_domain: dynamic.internal
3+
# coredns_dynamic_http_port:
4+
# coredns_dynamic_secret:
5+
coredns_dynamic_timeout: 2m
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=Coredns serivce discovery and dns server
3+
4+
[Service]
5+
Type=simple
6+
ExecStart=/usr/bin/coredns -conf /etc/coredns/Corefile
7+
WorkingDirectory=/etc/coredns
8+
9+
[Install]
10+
WantedBy=multi-user.target

roles/cs.coredns/meta/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dependencies:
2+
- name: cs.repo-mageops

roles/cs.coredns/tasks/disable.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- name: Update dhclient config
2+
template:
3+
dest: /etc/dhcp/dhclient.conf
4+
src: dhclient.conf.j2
5+
register: _update_dhclient
6+
7+
- name: Restart network
8+
service:
9+
name: network
10+
state: restarted
11+
when: _update_dhclient is changed
12+
13+
- name: Disable coredns service
14+
service:
15+
name: coredns
16+
state: stopped
17+
enabled: no
18+
19+
- name: Remove coredns config
20+
file:
21+
path: /etc/coredns/Corefile
22+
state: absent
23+
24+
- name: Remove coredns service file
25+
file:
26+
path: /etc/systemd/system/coredns.service
27+
state: absent
28+
29+
- name: Uninstall coredns
30+
yum:
31+
name: coredns
32+
state: absent

roles/cs.coredns/tasks/enable.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
- name: Install coredns
2+
yum:
3+
name: coredns
4+
state: latest
5+
6+
- name: Install service file
7+
copy:
8+
dest: /etc/systemd/system/coredns.service
9+
src: coredns.service
10+
11+
- name: Create coredns config directory
12+
file:
13+
name: /etc/coredns
14+
state: directory
15+
16+
- name: Configure coredns
17+
template:
18+
dest: /etc/coredns/Corefile
19+
src: Corefile.j2
20+
register: _corefile
21+
22+
- name: Restart coredns service
23+
service:
24+
name: coredns
25+
state: restarted
26+
enabled: yes
27+
when: _corefile is changed
28+
29+
- name: Enable coredns service
30+
service:
31+
name: coredns
32+
state: started
33+
enabled: yes
34+
when: _corefile is not changed
35+
36+
- name: Update dhclient config
37+
template:
38+
dest: /etc/dhcp/dhclient.conf
39+
src: dhclient.conf.j2
40+
register: _update_dhclient
41+
42+
- name: Restart network
43+
service:
44+
name: network
45+
state: restarted
46+
when: _update_dhclient is changed

roles/cs.coredns/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- name: Enable coredns
2+
include_tasks: enable.yml
3+
when: coredns_dynamic_enabled
4+
- name: Disable coredns
5+
include_tasks: disable.yml
6+
when: not coredns_dynamic_enabled
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% if coredns_dynamic_enabled %}
2+
{{ coredns_dynamic_domain }}:53 {
3+
bind 127.0.0.53
4+
dynamic {
5+
addr :{{ coredns_dynamic_http_port }}
6+
secret {{ coredns_dynamic_secret }}
7+
host_timeout {{ coredns_dynamic_timeout }}
8+
}
9+
}
10+
{% endif %}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% if coredns_dynamic_enabled %}
2+
prepend domain-name-servers 127.0.0.53;
3+
{% endif %}
4+
timeout 300;
5+
retry 60;

0 commit comments

Comments
 (0)