Skip to content

Commit

Permalink
Add GPU support for docker
Browse files Browse the repository at this point in the history
This implements kubernetes-sigs#3164
  • Loading branch information
samos123 committed May 30, 2023
1 parent 5dfe280 commit 8ca69b3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/config/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/internal/providers/docker/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/apis/config/convert_v1alpha4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 4 additions & 0 deletions pkg/internal/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions site/content/docs/user/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ca69b3

Please sign in to comment.