kubernetes/kops · error

reading IMDS response: %w

Error message

reading IMDS response: %w

What it means

queryIMDS failed while reading the IMDS response body via io.ReadAll, wrapped as "reading IMDS response". This happens when the connection drops mid-response or the read exceeds the client's 10s timeout — the headers arrived but the body could not be fully read.

Source

Thrown at upup/pkg/fi/cloudup/azure/azuremetadata/imds.go:90

	params.Set("api-version", imdsAPIVersion)
	req.URL.RawQuery = params.Encode()

	klog.V(4).Infof("Azure IMDS query: %q", req.URL.String())

	resp, err := imdsHTTPClient.Do(req)
	if err != nil {
		return fmt.Errorf("querying IMDS %s: %w", path, err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("querying IMDS %s: status %d", path, resp.StatusCode)
	}

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("reading IMDS response: %w", err)
	}
	klog.V(4).Infof("Azure IMDS response: %d bytes", len(body))

	if err := json.Unmarshal(body, result); err != nil {
		return fmt.Errorf("unmarshalling IMDS response: %w", err)
	}

	return nil
}

// QueryComputeInstanceMetadata queries Azure IMDS for compute instance metadata.
// https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service#instance-metadata
func QueryComputeInstanceMetadata(ctx context.Context) (*InstanceMetadata, error) {
	metadata := &InstanceMetadata{}
	params := url.Values{"format": {"json"}}
	if err := queryIMDS(ctx, "/metadata/instance/compute", params, metadata); err != nil {
		return nil, err
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Retry the query — this is almost always transient; callers of CreateToken typically retry bootstrap
  2. Check node network health (NIC, routes to link-local) if persistent
  3. Inspect for middleboxes/firewalls resetting established connections to 169.254.169.254
Defensive patterns

Strategy: retry

Try / catch

// Body-read failures are transient: retry the whole query
err := retry.OnError(wait.Backoff{Steps: 4, Duration: time.Second, Factor: 2},
    func(err error) bool { return strings.Contains(err.Error(), "reading IMDS response") },
    func() error { _, err := auth.CreateToken(body); return err })

Prevention

When it happens

Trigger: io.ReadAll(resp.Body) returns an error for an IMDS response: abrupt connection reset, truncated response, or timeout during body transfer from /metadata/instance/compute or /metadata/attested/document.

Common situations: Flaky virtual network / NIC issues on the node; IMDS under extreme load closing connections; very short-lived transient network partitions.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/8ac978b8a82d25c3. Report an issue: GitHub.