{"record":{"id":"4575fefdcb20474b","repo":"kubernetes/kops","slug":"error-reading-local-ipv4-from-aws-metadata-v","errorCode":null,"errorMessage":"error reading local-ipv4 from AWS metadata: %v","messagePattern":"error reading local-ipv4 from AWS metadata: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/nodeup/command.go","lineNumber":511,"sourceCode":"\t\t// The node name is the DNS name that EC2 generates for IP-named instances, built from the\n\t\t// primary private IPv4 address. kops-controller derives it with the same formula when\n\t\t// issuing certificates, so the two always agree. IMDS local-hostname is not usable for\n\t\t// this: with a custom DHCP domain it differs from the generated name.\n\t\t//\n\t\t// An instance launched with a resource-based hostname keeps a resource-based name (it can\n\t\t// only change while the instance is stopped), so an IP-based node name would not match its\n\t\t// EC2 hostname; fail rather than join a misconfigured instance.\n\t\thostnameBytes, err := vfs.Context.ReadFile(\"metadata://aws/meta-data/local-hostname\")\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error reading local-hostname from AWS metadata: %v\", err)\n\t\t}\n\t\tif strings.HasPrefix(string(hostnameBytes), instanceID) {\n\t\t\treturn \"\", fmt.Errorf(\"instance %s was launched with a resource-based hostname; useIPBasedNodeNames requires subnets that assign IP-based hostnames\", instanceID)\n\t\t}\n\n\t\tlocalIPv4Bytes, err := vfs.Context.ReadFile(\"metadata://aws/meta-data/local-ipv4\")\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error reading local-ipv4 from AWS metadata: %v\", err)\n\t\t}\n\t\tlocalIPv4 := string(localIPv4Bytes)\n\t\tif net.ParseIP(localIPv4).To4() == nil {\n\t\t\treturn \"\", fmt.Errorf(\"local-ipv4 from AWS metadata is not a valid IPv4 address: %q\", localIPv4)\n\t\t}\n\n\t\treturn awsbootstrap.PrivateDNSName(localIPv4, region), nil\n\n\tcase api.CloudProviderGCE:\n\t\t// This lets us tolerate broken hostnames (i.e. systemd)\n\t\tb, err := vfs.Context.ReadFile(\"metadata://gce/instance/hostname\")\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error reading hostname from GCE metadata: %v\", err)\n\t\t}\n\n\t\t// We only want to use the first portion of the fully-qualified name\n\t\t// e.g. foo.c.project.internal => foo\n\t\tfullyQualified := string(b)","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/command.go#L493-L529","documentation":"With useIPBasedNodeNames on AWS, nodeup reads 'metadata://aws/meta-data/local-ipv4' to build the IP-based node name. If the metadata read fails, it wraps the error with this message and aborts hostname evaluation.","triggerScenarios":"vfs.Context.ReadFile(\"metadata://aws/meta-data/local-ipv4\") errors after the local-hostname check passed: IMDS became unreachable, token expiry/network reset, or metadata endpoint disabled mid-run.","commonSituations":"Flaky IMDS access during boot (throttling when many metadata keys fetched concurrently); link-local blocked by host firewall; containerized nodeup with hop limit 1.","solutions":["Retry nodeup — transient IMDS failures during boot are common.","Verify local-ipv4 is readable: curl http://169.254.169.254/latest/meta-data/local-ipv4.","Raise hop limit to >=2 and confirm metadata endpoint enabled if containerized.","Check for host-level firewalls (iptables/nftables) blocking 169.254.169.254."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"curl -sf http://169.254.169.254/latest/meta-data/local-ipv4 | grep -E '^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$'","typeGuard":null,"tryCatchPattern":"override, err := evaluateHostnameOverride(api.CloudProviderAWS, true, region)\nif err != nil && strings.Contains(err.Error(), \"error reading local-ipv4\") {\n    // transient IMDS failure: retry once before giving up\n    time.Sleep(2 * time.Second)\n    override, err = evaluateHostnameOverride(api.CloudProviderAWS, true, region)\n}","preventionTips":["Pre-flight check local-ipv4 metadata before running nodeup.","Keep hop limit >=2 and endpoint enabled for containerized nodeup.","Avoid aggressive concurrency against IMDS at instance boot.","Ensure host firewalls allow link-local traffic."],"tags":["aws","imds","metadata","network"],"backgroundTag":"imds-unreachable","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}