Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consul: Add a nameserver entry poining to localhost for dnsmasq #571

Merged
merged 7 commits into from
Feb 3, 2024

Conversation

vitabaks
Copy link
Owner

@vitabaks vitabaks commented Feb 3, 2024

This update sets 127.0.0.1 as the nameserver in /etc/resolv.conf when Consul is utilized as the DCS. This change ensures proper resolution of Consul service DNS names, such as master.postgres-cluster.service.consul and replica.postgres-cluster.service.consul

Add support for DNS forwarding using Dnsmasq by conditionally setting 127.0.0.1 as the nameserver when Consul is used as the DCS.
@vitabaks vitabaks self-assigned this Feb 3, 2024
@vitabaks
Copy link
Owner Author

vitabaks commented Feb 3, 2024

Test

...

TASK [deploy-finish : PostgreSQL list of users] ********************************
ok: [10.172.0.20] => {
    "users_result.stdout_lines": [
        "                              List of roles",
        " Role name  |                         Attributes                         ",
        "------------+------------------------------------------------------------",
        " pgbouncer  | ",
        " postgres   | Superuser, Create role, Create DB, Replication, Bypass RLS",
        " replicator | Replication"
    ]
}

TASK [deploy-finish : Get postgresql database list] ****************************
ok: [10.172.0.20]

TASK [deploy-finish : PostgreSQL list of databases] ****************************
ok: [10.172.0.20] => {
    "dbs_result.stdout_lines": [
        "   name   |  owner   | encoding |   collate   |    ctype    |  size   | tablespace ",
        "----------+----------+----------+-------------+-------------+---------+------------",
        " postgres | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 7492 kB | pg_default",
        "(1 row)"
    ]
}

TASK [deploy-finish : Check postgresql cluster health] *************************
ok: [10.172.0.20]

TASK [deploy-finish : PostgreSQL Cluster health] *******************************
ok: [10.172.0.20] => {
    "patronictl_result.stdout_lines": [
        "+ Cluster: postgres-cluster (7331448813020401589) --+-----------+",
        "| Member   | Host        | Role    | State     | TL | Lag in MB |",
        "+----------+-------------+---------+-----------+----+-----------+",
        "| pgnode01 | 10.172.0.20 | Leader  | running   |  2 |           |",
        "| pgnode02 | 10.172.0.21 | Replica | streaming |  2 |         0 |",
        "| pgnode03 | 10.172.0.22 | Replica | streaming |  2 |         0 |",
        "+----------+-------------+---------+-----------+----+-----------+"
    ]
}

TASK [deploy-finish : PostgreSQL Cluster connection info] **********************
ok: [10.172.0.20] => {
    "msg": [
        "+------------------------------------------------+",
        "Client access point (DNS):",
        " master.postgres-cluster.service.consul ",
        " replica.postgres-cluster.service.consul ",
        "port 6432 (pgbouncer)",
        "+------------------------------------------------+"
    ]
}

PLAY RECAP *********************************************************************
10.172.0.20                : ok=181  changed=83   unreachable=0    failed=0    skipped=551  rescued=0    ignored=0
10.172.0.21                : ok=149  changed=73   unreachable=0    failed=0    skipped=518  rescued=0    ignored=0
10.172.0.22                : ok=149  changed=73   unreachable=0    failed=0    skipped=518  rescued=0    ignored=0

root@pgnode01:/# cat /etc/dnsmasq.d/10-consul
server=/consul/127.0.0.1#8600
server=8.8.8.8
server=9.9.9.9
root@pgnode01:/# cat /etc/resolv.conf 
nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 9.9.9.9
options ndots:0
root@pgnode01:/# psql -h master.postgres-cluster.service.consul -p 6432 -U postgres -c "select pg_is_in_recovery()";
 pg_is_in_recovery 
-------------------
 f
(1 row)

root@pgnode01:/# psql -h replica.postgres-cluster.service.consul -p 6432 -U postgres -c "select pg_is_in_recovery()";
 pg_is_in_recovery 
-------------------
 t
(1 row)

passed

@vitabaks vitabaks merged commit 139535c into master Feb 3, 2024
17 checks passed
@vitabaks vitabaks deleted the consul-resolv-conf branch February 3, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant