Jenkins Pipeline DNS Lookup Fails for CloudMap‑Registered AI Service on EC2
Problem
The Jenkins CI/CD pipeline attempts to invoke an AI inference endpoint that is registered in AWS CloudMap. During the deploy and test stages the pipeline logs show DNS resolution errors such as:
[ERROR] Failed to resolve host: ai-inference.myservice.local
java.net.UnknownHostException: ai-inference.myservice.local
Consequences:
- Deployment jobs abort before container start‑up.
- Integration tests that call the model endpoint cannot run.
- Pipeline stability degrades, leading to missed releases.
Root Cause
The failure originates from a mismatch between the DNS namespace configuration in CloudMap and the network environment of the Jenkins agents:
- AI services run on EC2 instances inside a private subnet with a custom VPC DNS resolver (AmazonProvidedDNS).
- Jenkins agents are provisioned in a separate public subnet that does not have
enableDnsHostnamesandenableDnsSupportset consistently across the VPC. - The CloudMap namespace was created as a private DNS namespace (type
DNS_PRIVATE) scoped to the VPC. DNS queries from the public subnet are forwarded to the VPC resolver, but the resolver cannot reach the private DNS server because theroute‑53resolverinbound endpoint is missing. - Additionally, the EC2 instances register their IPs using the
Arecord type, but the Jenkins container runs inside a Docker network that overrides/etc/resolv.confwith the host’s DNS (pointing to 8.8.8.8), bypassing the VPC resolver entirely.
In short, the pipeline cannot reach the private CloudMap DNS because the DNS path is broken at two points: VPC DNS support and container DNS configuration.
Debug
Step‑by‑step investigation that reproduced the issue:
- Inspect Jenkins agent DNS configuration
$ cat /etc/resolv.conf
nameserver 8.8.8.8
options ndots:2
search ec2.internal
The resolver points to Google DNS, not the VPC resolver (169.254.169.253).
- Validate CloudMap namespace resolution from inside the VPC
$ dig ai-inference.myservice.local @169.254.169.253 +short
10.0.12.45
Works when queried directly against the VPC resolver.
- Attempt resolution from the Jenkins agent
$ dig ai-inference.myservice.local +short
;; connection timed out; no servers could be reached
No response because the agent never reaches the VPC resolver.
- Check VPC DNS settings
aws ec2 describe-vpcs --vpc-ids vpc-0a1b2c3d4e5f6g7h \
--query 'Vpcs[].{DnsSupport:EnableDnsSupport,DnsHostnames:EnableDnsHostnames}'
{
"DnsSupport": true,
"DnsHostnames": false
}
Hostnames are disabled, preventing private DNS names from being resolvable from EC2 instances that lack an Elastic IP.
- Verify inbound Route 53 Resolver endpoint
aws route53resolver list-resolver-endpoints --filters Name=Direction,Values=INBOUND
{
"ResolverEndpoints": []
}
No inbound endpoint exists, so cross‑subnet DNS queries are dropped.
Solution
Apply three coordinated changes:
1. Enable DNS hostnames for the VPC
aws ec2 modify-vpc-attribute --vpc-id vpc-0a1b2c3d4e5f6g7h \
--enable-dns-hostnames "{\"Value\":true}"
2. Deploy a Route 53 Resolver inbound endpoint in the public subnet
aws route53resolver create-resolver-endpoint \
--name ci-dns-inbound \
--direction INBOUND \
--security-group-ids sg-0123456789abcdef0 \
--ip-addresses SubnetId=subnet-11111111,Ip=10.0.1.10 \
SubnetId=subnet-22222222,Ip=10.0.2.10
Update the Jenkins agent’s /etc/resolv.conf to point to the inbound endpoint IPs (e.g., 10.0.1.10 and 10.0.2.10).
3. Preserve VPC DNS inside Docker containers
When launching the Jenkins agent container, bind the host’s resolver configuration:
docker run -d \
--name jenkins-agent \
-v /etc/resolv.conf:/etc/resolv.conf:ro \
-e DOCKER_HOST=unix:///var/run/docker.sock \
jenkins/inbound-agent:latest
Alternatively, set the Docker daemon’s --dns flag to the VPC resolver:
dockerd --dns 169.254.169.253 --dns 10.0.1.10
Before / After Comparison
| Aspect | Before | After |
|---|---|---|
| VPC DNS Hostnames | Disabled | Enabled |
| Resolver Endpoint | None | Inbound endpoint present |
| Jenkins DNS Config | External (8.8.8.8) | VPC resolver (169.254.169.253) |
| Container DNS | Overridden by Docker | Host /etc/resolv.conf mounted |
Verify
Run the same checks that previously failed:
# From Jenkins agent
$ cat /etc/resolv.conf
nameserver 10.0.1.10
nameserver 10.0.2.10
search myservice.local
$ dig ai-inference.myservice.local +short
10.0.12.45
Execute a pipeline stage that curls the AI endpoint:
$ curl -s http://ai-inference.myservice.local/health
{"status":"ok"}
Metrics to watch:
- Route 53 Resolver query count (CloudWatch metric
ResolverQueryCount) should increase without errors. - Jenkins job logs no longer contain
UnknownHostException. - Deployment latency returns to baseline (< 30 s).
Prevent
- Infrastructure as Code: Encode VPC DNS settings and Resolver endpoints in Terraform/CloudFormation to guarantee consistency across environments.
- Health‑check Lambda: Periodically query a known CloudMap record from each subnet; raise an alarm if resolution fails.
- Docker DNS Policy: Enforce a policy that containers inherit the host resolver or explicitly set
--dnsto the VPC resolver. - CI/CD Agent Image: Bake the correct
/etc/resolv.confinto the agent image and lock the DNS IPs via environment variables. - Monitoring: Create CloudWatch dashboards for
ResolverQueryCountandResolverQueryFailureto detect future outages early.
FAQ
- Why does the DNS failure only appear in the Jenkins pipeline and not when I SSH into the EC2 instance?
The EC2 instance uses the VPC resolver directly, while the Jenkins agent runs inside Docker with its own/etc/resolv.confthat points to an external DNS server. The discrepancy hides the problem on the instance. - Can I use a public CloudMap namespace instead of a private one?
Public namespaces are intended for services exposed to the internet and require Route 53 public hosted zones. For internal AI inference services a private namespace is preferred; using a public namespace would expose internal IPs and increase attack surface. - Do I need to restart the Jenkins agent after changing
/etc/resolv.conf?
Yes. Docker caches the resolver file at container start. Either restart the container or mount the file as read‑only so that updates propagate on the next container launch. - What if I cannot modify the VPC DNS settings (e.g., shared VPC)?
Deploy a local DNS forwarder (e.g.,coredns) in the same subnet as the Jenkins agents, configure it to forward.myservice.localqueries to the VPC resolver, and point the agents’--dnsflag to the forwarder. - How do I troubleshoot intermittent DNS timeouts after the fix?
Check the inbound resolver endpoint’s ENI health, verify security group rules allow UDP/TCP port 53 from the Jenkins subnet, and inspect CloudWatch metrics for spikes inResolverQueryTimeout. Scaling the resolver endpoint (adding a second AZ) often resolves intermittent latency.
Related Topic Hub: Cloud Infrastructure Troubleshooting Hub