kubernetes/kops · error

failed to get instance metadata type: %w

Error message

failed to get instance metadata type: %w

What it means

After loading AWS config, getMachineType queries the EC2 Instance Metadata Service at path 'instance-type' via the SDK's IMDS client. If that GetMetadata call fails (network, token, or endpoint error), nodeup wraps it with this message and cannot determine the machine type.

Source

Thrown at upup/pkg/fi/nodeup/command.go:422

		}
	}
	return nil
}

func getMachineType(ctx context.Context) (string, error) {
	config, err := awsconfig.LoadDefaultConfig(ctx)
	if err != nil {
		return "", fmt.Errorf("failed to load AWS config: %w", err)
	}

	metadata := imds.NewFromConfig(config)

	// Get the actual instance type by querying the EC2 instance metadata service.
	result, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{
		Path: "instance-type",
	})
	if err != nil {
		return "", fmt.Errorf("failed to get instance metadata type: %w", err)
	}
	defer result.Content.Close()
	instanceTypeName, err := io.ReadAll(result.Content)
	if err != nil {
		return "", fmt.Errorf("failed to read instance metadata response: %w", err)
	}
	return string(instanceTypeName), err
}

func completeWarmingLifecycleAction(ctx context.Context, cloud *awsup.Cloud, modelContext *model.NodeupModelContext) error {
	asgName := modelContext.BootConfig.InstanceGroupName + "." + modelContext.NodeupConfig.ClusterName
	hookName := "kops-warmpool"
	hooks, err := cloud.DescribeLifecycleHooks(ctx, &autoscaling.DescribeLifecycleHooksInput{
		AutoScalingGroupName: &asgName,
		LifecycleHookNames:   []string{hookName},
	})
	if err != nil {
		return fmt.Errorf("failed to find lifecycle hook %q: %w", hookName, err)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify metadata access from the node: curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-type.
  2. Raise --http-put-response-hop-limit to 2+ if nodeup runs in a container.
  3. Re-enable the metadata endpoint if the instance was launched with metadata disabled.
  4. Retry after transient failure — IMDS token fetches can be throttled during fleet-wide scale-up events.
Defensive patterns

Strategy: retry

Validate before calling

curl -sf http://169.254.169.254/latest/meta-data/instance-type || echo 'IMDS unreachable pre-flight failure'

Try / catch

result, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{Path: "instance-type"})
if err != nil {
    var rerr *retry.Error
    if errors.As(err, &rerr) {
        // throttled/transient: back off and retry with jitter
    }
    return fmt.Errorf("IMDS metadata query failed: %w", err)
}

Prevention

When it happens

Trigger: imds.NewFromConfig(config).GetMetadata(ctx, {Path: "instance-type"}) returns an error: IMDS endpoint unreachable, IMDSv2 token request denied, metadata service disabled on the instance, or transient network failure.

Common situations: Nodeup running inside a container/network namespace that blocks 169.254.169.254; IMDSv2 with hop limit 1 while nodeup is one hop away; instance launched with metadata disabled (HttpEndpoint disabled); brief IMDS throttling at instance boot.

Related errors


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