-
Notifications
You must be signed in to change notification settings - Fork 184
Fix GCP Consul DNS resolution with two-layer protection #1430
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e8ad749
Fix GCP Consul DNS resolution with two-layer protection
tomassrnka 6123dea
Merge branch 'main' into 2025-11-03-gcp-consul-dns
tomassrnka c75b85f
Update start-client.sh
tomassrnka 9fbd28e
Replaced sleep with actual check on systemd-resolved restart
tomassrnka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,9 +184,16 @@ cat <<EOF >/etc/systemd/resolved.conf.d/consul.conf | |
| [Resolve] | ||
| DNS=127.0.0.1:8600 | ||
| DNSSEC=false | ||
| Domains=~consul | ||
| EOF | ||
| systemctl restart systemd-resolved | ||
| sync # Ensure file is written to disk | ||
|
|
||
| # Remove GCE's DNS config to prevent it from competing with Consul DNS (GCP-specific fix) | ||
| # We don't need routing domains since Consul handles ALL DNS: | ||
| # - .consul queries: served directly by Consul | ||
| # - other queries: forwarded to GCE DNS via Consul's recursor config | ||
| if [ -f /etc/systemd/resolved.conf.d/gce-resolved.conf ]; then | ||
| mv /etc/systemd/resolved.conf.d/gce-resolved.conf /etc/systemd/resolved.conf.d/gce-resolved.conf.disabled | ||
| fi | ||
|
|
||
| # Set up huge pages | ||
| # We are not enabling Transparent Huge Pages for now, as they are not swappable and may result in slowdowns + we are not using swap right now. | ||
|
|
@@ -260,13 +267,36 @@ overcommitment_hugepages=$(remove_decimal $overcommitment_hugepages) | |
| echo "- Allocating $overcommitment_hugepages huge pages ($overcommitment_hugepages_percentage%) for overcommitment" | ||
| echo $overcommitment_hugepages >/proc/sys/vm/nr_overcommit_hugepages | ||
|
|
||
| # Get GCE DNS server dynamically from metadata for Consul recursors | ||
| # This ensures we can resolve internet domains through Consul | ||
| GCE_DNS=$(curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/dns-servers || echo "169.254.169.254") | ||
|
|
||
| # Start Consul first (in background) with GCE DNS as recursor | ||
| # This allows Consul to handle both .consul queries AND forward internet queries | ||
| # These variables are passed in via Terraform template interpolation | ||
| /opt/consul/bin/run-consul.sh --client \ | ||
| --consul-token "${CONSUL_TOKEN}" \ | ||
| --cluster-tag-name "${CLUSTER_TAG_NAME}" \ | ||
| --enable-gossip-encryption \ | ||
| --gossip-encryption-key "${CONSUL_GOSSIP_ENCRYPTION_KEY}" \ | ||
| --dns-request-token "${CONSUL_DNS_REQUEST_TOKEN}" & | ||
| --dns-request-token "${CONSUL_DNS_REQUEST_TOKEN}" \ | ||
| --recursor "$${GCE_DNS}" & | ||
|
|
||
| # Give Consul a moment to start its DNS server on port 8600 | ||
| sleep 3 | ||
|
|
||
| # Now restart systemd-resolved to apply Consul DNS configuration | ||
| # This must happen AFTER Consul starts, otherwise systemd-resolved marks 127.0.0.1:8600 as unreachable | ||
| # Consul DNS (127.0.0.1:8600) is the ONLY DNS server configured in systemd-resolved | ||
| # Consul handles ALL queries: .consul directly, everything else via recursor to GCE DNS | ||
| echo "[Configuring systemd-resolved for Consul DNS]" | ||
| echo "- Restarting systemd-resolved to apply Consul DNS config" | ||
| systemctl restart systemd-resolved | ||
| echo "- Waiting for systemd-resolved to settle" | ||
| sleep 5 | ||
|
||
| echo "- Flushing DNS caches" | ||
| resolvectl flush-caches | ||
| echo "- systemd-resolved configured to use Consul DNS for all queries" | ||
|
|
||
| /opt/nomad/bin/run-nomad.sh --client --consul-token "${CONSUL_TOKEN}" --node-pool "${NODE_POOL}" & | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.