diff --git a/pkg/apis/config/v1alpha4/types.go b/pkg/apis/config/v1alpha4/types.go index 308a6853b8..8ac93a1944 100644 --- a/pkg/apis/config/v1alpha4/types.go +++ b/pkg/apis/config/v1alpha4/types.go @@ -118,6 +118,10 @@ type Node struct { // binded to a host Port ExtraPortMappings []PortMapping `yaml:"extraPortMappings,omitempty" json:"extraPortMappings,omitempty"` + // GPUs allows to access GPU devices from the kind node. Setting this to + // "all" will pass all the available GPUs to the kind node. + Gpus string `yaml:"gpus,omitempty" json:"gpus,omitempty"` + // KubeadmConfigPatches are applied to the generated kubeadm config as // merge patches. The `kind` field must match the target object, and // if `apiVersion` is specified it will only be applied to matching objects. diff --git a/pkg/cluster/internal/providers/docker/provision.go b/pkg/cluster/internal/providers/docker/provision.go index 6c644a3651..0969f21f82 100644 --- a/pkg/cluster/internal/providers/docker/provision.go +++ b/pkg/cluster/internal/providers/docker/provision.go @@ -255,6 +255,10 @@ func runArgsForNode(node *config.Node, clusterIPFamily config.ClusterIPFamily, n args = append(args, "-e", "KUBECONFIG=/etc/kubernetes/admin.conf") } + if len(node.Gpus) > 0 { + args = append(args, fmt.Sprintf("--gpus=%v", node.Gpus)) + } + // finally, specify the image to run return append(args, node.Image), nil } diff --git a/pkg/internal/apis/config/convert_v1alpha4.go b/pkg/internal/apis/config/convert_v1alpha4.go index 2df4b75138..ed934817dd 100644 --- a/pkg/internal/apis/config/convert_v1alpha4.go +++ b/pkg/internal/apis/config/convert_v1alpha4.go @@ -56,6 +56,7 @@ func convertv1alpha4Node(in *v1alpha4.Node, out *Node) { out.ExtraMounts = make([]Mount, len(in.ExtraMounts)) out.ExtraPortMappings = make([]PortMapping, len(in.ExtraPortMappings)) out.KubeadmConfigPatchesJSON6902 = make([]PatchJSON6902, len(in.KubeadmConfigPatchesJSON6902)) + out.Gpus = in.Gpus for i := range in.ExtraMounts { convertv1alpha4Mount(&in.ExtraMounts[i], &out.ExtraMounts[i]) diff --git a/pkg/internal/apis/config/types.go b/pkg/internal/apis/config/types.go index fed3000798..81067ae224 100644 --- a/pkg/internal/apis/config/types.go +++ b/pkg/internal/apis/config/types.go @@ -98,6 +98,10 @@ type Node struct { // binded to a host Port ExtraPortMappings []PortMapping + // GPUs allows to access GPU devices from the kind node. Setting this to + // "all" will pass all the available GPUs to the kind node. + Gpus string + // KubeadmConfigPatches are applied to the generated kubeadm config as // strategic merge patches to `kustomize build` internally // https://github.com/kubernetes/community/blob/a9cf5c8f3380bb52ebe57b1e2dbdec136d8dd484/contributors/devel/sig-api-machinery/strategic-merge-patch.md diff --git a/site/content/docs/user/configuration.md b/site/content/docs/user/configuration.md index 64bb6b5574..98afabaa88 100644 --- a/site/content/docs/user/configuration.md +++ b/site/content/docs/user/configuration.md @@ -285,6 +285,20 @@ nodes: **Note**: Kubernetes versions are expressed as x.y.z, where x is the major version, y is the minor version, and z is the patch version, following [Semantic Versioning](https://semver.org/) terminology. For more information, see [Kubernetes Release Versioning.](https://github.com/kubernetes/sig-release/blob/master/release-engineering/versioning.md#kubernetes-release-versioning) +### GPU Support + +Kind nodes can utilize GPUs by setting the following: +{{< codeFromInline lang="yaml" >}} +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + gpus: all +{{< /codeFromInline >}} + +As a pre-requisite you need to have installed the +[NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html). + ### Extra Mounts Extra mounts can be used to pass through storage on the host to a kind node