Skip to content
DocsTry Aspire
DocsTry

KindContainerExtensions Methods

ClassMethods2 members
Extension methods for configuring container resources to work with Kind clusters.
WithKindNetwork(IResourceBuilder<ContainerResource>)Section titled WithKindNetwork(IResourceBuilder<ContainerResource>)extensionIResourceBuilder<ContainerResource>
Connects a container resource to the Kind container network, enabling it to communicate with the Kind cluster's API server and nodes.
public static class KindContainerExtensions
{
public static IResourceBuilder<ContainerResource> WithKindNetwork(
this IResourceBuilder<ContainerResource> builder)
{
// ...
}
}
builderIResourceBuilder<ContainerResource>The container resource builder.
IResourceBuilder<ContainerResource>A reference to the ApplicationModel.IResourceBuilder`1.

Use this method when a container needs direct network connectivity to the Kind control plane.

Kind creates a separate container network ("kind") for its nodes. Aspire manages its own container network for containers it creates. Containers on different networks cannot communicate by default.

Aspire does not provide a built-in way to add containers to additional container networks, and WithContainerRuntimeArgs("--network", "kind") is overridden internally. See https://github.com/microsoft/aspire/issues/14081 for the upstream feature request.

This method works around the limitation by subscribing to the container's stopped event. When the container stops (typically because it can't reach the Kind cluster), the hook connects the container to the "kind" network via the configured container runtime and restarts it.

If the container does not already have an explicit name (via WithContainerName), this method assigns one using the pattern {resource.Name}-{random} to ensure the container can be identified by the handler.

WithReference(IResourceBuilder<ContainerResource>, IResourceBuilder<KindClusterResource>)Section titled WithReference(IResourceBuilder<ContainerResource>, IResourceBuilder<KindClusterResource>)extensionIResourceBuilder<ContainerResource>
Configures a container resource to reference the Kind cluster by bind-mounting the container-compatible kubeconfig, injecting environment variables, and connecting to the Kind container network.
public static class KindContainerExtensions
{
public static IResourceBuilder<ContainerResource> WithReference(
this IResourceBuilder<ContainerResource> builder,
IResourceBuilder<KindClusterResource> kind)
{
// ...
}
}
builderIResourceBuilder<ContainerResource>The container resource builder.
kindIResourceBuilder<KindClusterResource>The Kind cluster resource builder.
IResourceBuilder<ContainerResource>A reference to the ApplicationModel.IResourceBuilder`1.

This overload is the primary integration path for containers. It:

  • Bind-mounts the container-compatible kubeconfig into the container at /etc/kubeconfig/config
  • Sets KUBECONFIG to the in-container mount path
  • Sets K8S_CLUSTER_NAME to the Kind cluster name
  • Automatically connects the container to the Kind network

The container-compatible kubeconfig uses the Kind control-plane container name ( {clusterName}-control-plane) instead of 127.0.0.1, enabling container-to-container communication over the Kind container network.