Skip to content
GPU infrastructure on Kubernetes · Chapter 8 of 19 Day 6: MIG – Cutting a GPU into Real Pieces

Day 6: MIG – Cutting a GPU into Real Pieces

Goal: Split A100 GPUs into separate instances with Multi-Instance GPU (MIG), offer them as resources with the single and mixed strategies, and understand the hardware’s placement rules · Duration: approx. 75 min · Prerequisite: Day 5

Briefing

  • MIG splits a GPU in hardware: each instance gets its own compute units, its own memory and its own memory bandwidth. A Pod on one instance can neither slow down the others nor crash them. That is the difference from time-slicing.
  • Not every GPU can do this: A100, H100 and newer data center cards can, T4 and L40S cannot (GFD label nvidia.com/mig.capable).
  • The names say what an instance has: 1g.5gb = one seventh of the compute and 5 GB of memory, 3g.20gb = three sevenths and 20 GB.
  • Two strategies in the device plugin:
Strategy Resource in the cluster Prerequisite
single each instance as nvidia.com/gpu all instances on a node the same size
mixed a separate resource per size, e.g. nvidia.com/mig-3g.20gb any valid partitioning
  • Mokka simulates NVML’s MIG view, the device files and the placement rules of a real A100. A simulated instance cannot compute.

Drill 1: What an A100 Offers

For administrative commands you need a Pod that sees all GPUs, as on Day 1:

mkdir -p ~/gpu/tag06 && cd ~/gpu/tag06
kubectl create namespace tag06
cat > admin.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: admin
  namespace: tag06
  annotations:
    nvml-mock.nvidia.com/devices: "true"
spec:
  nodeSelector:
    gpu: mokka
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
EOF
kubectl apply -f admin.yaml
kubectl -n tag06 wait --for=condition=Ready pod/admin --timeout=90s
kubectl -n tag06 exec admin -- nvidia-smi --query-gpu=index,mig.mode.current --format=csv \
  | head -3

Expected (shortened):

index, mig.mode.current
0, Disabled
1, Disabled

MIG is off. A GPU with MIG disabled offers no profiles. With Mokka you enable it through the chart; on real hardware with nvidia-smi -i 0 -mig 1 or the GPU Operator’s MIG manager.

Save your progress? Sign up for free

Drill 2: Seven Equal Pieces

Each GPU is cut into seven 1g.5gb, the matching partitioning for single:

cat > mig-single.yaml <<EOF
gpu:
  profile: a100
  mig:
    enabled: true
    gpuInstances:
    - profile: "1g.5gb"
      count: 7
nodeSelector:
  gpu: mokka
EOF
helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 \
  -n mokka -f mig-single.yaml --wait --timeout 180s | grep STATUS
kubectl -n tag06 delete pod admin
kubectl apply -f admin.yaml
kubectl -n tag06 wait --for=condition=Ready pod/admin --timeout=90s
kubectl -n tag06 exec admin -- nvidia-smi mig -lgip -i 0

Expected (shortened):

STATUS: deployed
+-------------------------------------------------------------------------------+
| GPU instance profiles:                                                        |
| GPU   Name               ID    Instances   Memory     P2P    SM    DEC   ENC  |
|                                Free/Total   GiB              CE    JPEG  OFA  |
|===============================================================================|
|   0  MIG 1g.5gb          19     0/7        4.75       No     14     0     0   |
|   0  MIG 1g.10gb         15     0/4        9.62       No     14     1     0   |
|   0  MIG 2g.10gb         14     0/3        9.62       No     28     1     0   |
|   0  MIG 3g.20gb          9     0/2        19.50      No     42     2     0   |
|   0  MIG 4g.20gb          5     0/1        19.50      No     56     2     0   |
|   0  MIG 7g.40gb          0     0/1        39.25      No     98     5     0   |
+-------------------------------------------------------------------------------+

The profile table of a real A100-40GB. Free 0/7 for 1g.5gb: all seven slots are taken, and so nothing is free for any other profile either.

kubectl -n tag06 exec admin -- nvidia-smi -L | head -4

Expected:

GPU 0: NVIDIA A100-SXM4-40GB (UUID: GPU-12345678-1234-1234-1234-123456780000)
  MIG 1g.5gb      Device  0: (UUID: MIG-12345678-1234-1234-0000-123456780000)
  MIG 1g.5gb      Device  1: (UUID: MIG-12345678-1234-1234-0100-123456780000)
  MIG 1g.5gb      Device  2: (UUID: MIG-12345678-1234-1234-0200-123456780000)

Each instance has its own MIG-… UUID.

Save your progress? Sign up for free

Drill 3: The Device Plugin Has to Know

What does the kubelet report now?

kubectl get node gpu-worker2 -o jsonpath='{.status.allocatable.nvidia\.com/gpu}{"\n"}'

Expected:

8

Eight whole GPUs, even though each one is cut into seven pieces. The device plugin is still running without a MIG strategy. A Pod would get a “whole” GPU that no longer exists as such. So add migStrategy: single to the configuration from Day 5:

printf 'version: v1\nflags:\n  migStrategy: single\n' > mig-single-plugin.yaml
kubectl -n kube-system create configmap gpu-sharing --from-file=config.yaml=mig-single-plugin.yaml \
  --dry-run=client -o yaml | kubectl replace -f -
kubectl -n kube-system rollout restart ds/nvidia-device-plugin-mock
sleep 20
kubectl -n kube-system get pods -l name=nvidia-device-plugin-mock
kubectl -n kube-system logs ds/nvidia-device-plugin-mock --previous | grep '^E' | tail -1 \
  | cut -c1-150

Expected (shortened):

NAME                              READY   STATUS   RESTARTS      AGE
nvidia-device-plugin-mock-82c59   0/1     Error    2 (19s ago)   22s
E1122 13:21:25.821357       1 main.go:185] error starting plugins: error getting plugins: unable to cre

The plugin crashes while building the MIG device table. For that it reads the file /proc/driver/nvidia-caps/mig-minors, which the driver creates on a real server. It does not exist in the kind node; Mokka puts a copy under the driver root. But nothing can be mounted under /proc. NVIDIA provides a tested DaemonSet for this that places the copy over /proc/driver inside the container. This is a quirk of the simulation; on real hardware it does not apply:

curl -sLO https://raw.githubusercontent.com/NVIDIA/k8s-test-infra/v0.7.0/\
tests/e2e/go/assets/device-plugin-mock-mig.yaml
grep -E 'mount -o bind|--mig-strategy' device-plugin-mock-mig.yaml
kubectl apply -f device-plugin-mock-mig.yaml
kubectl -n kube-system rollout status ds/nvidia-device-plugin-mock --timeout=180s | tail -1
sleep 12
kubectl get node gpu-worker2 -o custom-columns='CAP:.status.capacity.nvidia\.com/gpu,ALLOC:.status.allocatable.nvidia\.com/gpu'

Expected:

              mount -o bind "$staged" /proc/driver
            - "--mig-strategy=single"
daemonset.apps/nvidia-device-plugin-mock configured
daemon set "nvidia-device-plugin-mock" successfully rolled out
CAP   ALLOC
56    56

8 GPUs × 7 instances = 56. To Kubernetes, every instance is called nvidia.com/gpu.

Save your progress? Sign up for free

Drill 4: One Pod, One Instance

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: slice
  namespace: tag06
spec:
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/gpu: 1
EOF
kubectl -n tag06 wait --for=condition=Ready pod/slice --timeout=90s
kubectl -n tag06 exec slice -- printenv NVIDIA_VISIBLE_DEVICES
kubectl -n tag06 exec slice -- sh -c 'ls /dev | grep nvidia; ls /dev/nvidia-caps'

Expected:

pod/slice condition met
MIG-12345678-1234-1234-0500-123456780006
nvidia-caps
nvidia-uvm
nvidia-uvm-tools
nvidia6
nvidiactl
nvidia-cap97
nvidia-cap98

The Pod gets the MIG UUID, the parent GPU /dev/nvidia6 and two capability files: one for its GPU instance, one for its compute instance. Only through these two may it open its instance, not the other six on the same card.

A limit of the simulation: inside the Pod, nvidia-smi -L shows all seven instances of GPU 6. On real hardware the Pod would see only its one. What counts is what the Pod gets allocated, and that is exactly one instance.

Save your progress? Sign up for free

Drill 5: GFD Says What Really Exists

GFD gets the same strategy (the configuration file stays, see Day 5):

printf 'version: v1\nflags:\n  migStrategy: single\n' > gfd-mig.yaml
cp ~/gpu/tag03/gfd-werte.yaml gfd-mig-werte.yaml
printf 'config:\n  map:\n    default: |-\n%s\n' "$(sed 's/^/      /' gfd-mig.yaml)" >> gfd-mig-werte.yaml
helm upgrade gfd nvdp/nvidia-device-plugin --version 0.18.2 -n gpu-feature-discovery \
  -f gfd-mig-werte.yaml --wait --timeout 180s | grep STATUS
sleep 75
kubectl get node gpu-worker2 -o json | jq -r '.metadata.labels | to_entries[]
  | select(.key|test("nvidia.com/(gpu\\.(product|count|memory)|mig)")) | "\(.key)=\(.value)"'

Expected:

STATUS: deployed
nvidia.com/gpu.count=56
nvidia.com/gpu.memory=4864
nvidia.com/gpu.product=NVIDIA-A100-SXM4-40GB-MIG-1g.5gb
nvidia.com/mig.capable=true
nvidia.com/mig.strategy=single

56 “GPUs” with 4864 MiB each, product …-MIG-1g.5gb. A team with the affinity from Day 3 (“at least 32 GB”) no longer fits here. That is exactly how it should be.

Save your progress? Sign up for free

Drill 6: Different Sizes and the Placement Rules

One team needs a large instance, another a medium one, two testers a small one each. Planned: 3g.20gb + 2g.10gb + 2 × 1g.5gb, together 3 + 2 + 1 + 1 = 7 sevenths.

kubectl -n tag06 delete pod slice
cat > mig-mixed.yaml <<EOF
gpu:
  profile: a100
  mig:
    enabled: true
    gpuInstances:
    - profile: "3g.20gb"
      count: 1
    - profile: "2g.10gb"
      count: 1
    - profile: "1g.5gb"
      count: 2
nodeSelector:
  gpu: mokka
EOF
helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 \
  -n mokka -f mig-mixed.yaml --wait --timeout 180s | grep STATUS
sed 's/--mig-strategy=single/--mig-strategy=mixed/' device-plugin-mock-mig.yaml \
  > device-plugin-mock-mig-mixed.yaml
kubectl apply -f device-plugin-mock-mig-mixed.yaml
kubectl -n kube-system rollout status ds/nvidia-device-plugin-mock --timeout=180s | tail -1
sleep 15
kubectl get node gpu-worker2 -o json | jq -c '.status.allocatable
  | with_entries(select(.key|startswith("nvidia.com/mig")))'

Expected (shortened):

STATUS: deployed
daemon set "nvidia-device-plugin-mock" successfully rolled out
{"nvidia.com/mig-1g.5gb":"8","nvidia.com/mig-2g.10gb":"8","nvidia.com/mig-3g.20gb":"8"}

Separate resources per size, but only 8 small instances instead of 16. Why?

kubectl -n tag06 delete pod admin
kubectl apply -f admin.yaml
kubectl -n tag06 wait --for=condition=Ready pod/admin --timeout=90s
kubectl -n tag06 exec admin -- nvidia-smi mig -lgi -i 0 2>&1 | head -3
kubectl -n tag06 exec admin -- nvidia-smi mig -lgi -i 0 2>/dev/null | grep 'MIG '

Expected:

[MOCK_NVML WARNING] [MIG] device 0: cannot create declared "1g.5gb" instance: ERROR_INSUFFICIENT_RESOURCES
[MOCK_NVML WARNING] [MIG] device 1: cannot create declared "1g.5gb" instance: ERROR_INSUFFICIENT_RESOURCES
[MOCK_NVML WARNING] [MIG] device 2: cannot create declared "1g.5gb" instance: ERROR_INSUFFICIENT_RESOURCES
|   0  MIG 1g.5gb            19        2          6:1     |
|   0  MIG 2g.10gb           14        1          4:2     |
|   0  MIG 3g.20gb            9        0          0:4     |

The Placement Start:Size column explains it. An A100 has eight memory slots. 3g.20gb counts as three sevenths but occupies four memory slots (0 to 3), 2g.10gb two (4 and 5), 1g.5gb one (6). For the second small instance only slot 7 remains, and that one is not allowed for 1g.5gb. The arithmetic “3 + 2 + 1 + 1 = 7” is right for compute, not for the placement rules. Real A100s behave exactly the same. Valid partitionings are listed in NVIDIA’s MIG user guide, section “Supported MIG Profiles”.

A Pod requests the large instance specifically:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: gross
  namespace: tag06
spec:
  tolerations:
  - key: nvidia.com/gpu
    operator: Exists
    effect: NoSchedule
  containers:
  - name: c
    image: ubuntu:24.04
    command: [sleep, infinity]
    resources:
      limits:
        nvidia.com/mig-3g.20gb: 1
EOF
kubectl -n tag06 wait --for=condition=Ready pod/gross --timeout=90s
kubectl -n tag06 exec gross -- printenv NVIDIA_VISIBLE_DEVICES
kubectl describe node gpu-worker2 | sed -n '/Allocated resources/,/Events/p' | grep mig

Expected:

pod/gross condition met
MIG-12345678-1234-1234-0000-123456780003
  nvidia.com/mig-1g.5gb   0           0
  nvidia.com/mig-2g.10gb  0           0
  nvidia.com/mig-3g.20gb  1           1

Save your progress? Sign up for free

Exercise: Speed Drills

  1. Show which MIG resources the node offers. Target time: 1 min
  2. Show the placement of all instances on GPU 0. Target time: 1 min
  3. Show whether the node’s GPUs support MIG at all. Target time: 30 s

Solution

kubectl get node gpu-worker2 -o json | jq '.status.allocatable | with_entries(select(.key|startswith("nvidia.com/mig")))'
kubectl -n tag06 exec admin -- nvidia-smi mig -lgi -i 0 2>/dev/null
kubectl get node gpu-worker2 -o jsonpath='{.metadata.labels.nvidia\.com/mig\.capable}{"\n"}'

Save your progress? Sign up for free

Checkpoint

kubectl get node gpu-worker2 -o jsonpath='{.status.allocatable.nvidia\.com/mig-3g\.20gb}{"\n"}'

Expected: 8

kubectl -n tag06 get pod gross -o jsonpath='{.status.phase}{"\n"}'

Expected: Running

Challenge

Go back to eight whole A100s, without MIG, for Day 7. Mokka, the device plugin and GFD must agree afterwards.

Hint: Three components, three values files that already exist.

Solution

kubectl delete namespace tag06
helm upgrade nvml-mock oci://ghcr.io/nvidia/k8s-test-infra/chart/nvml-mock --version 0.7.0 \
  -n mokka -f ~/gpu/tag00/mokka-werte.yaml --wait --timeout 180s | grep STATUS
kubectl apply -f ~/gpu/tag02/device-plugin-mock.yaml
kubectl -n kube-system rollout status ds/nvidia-device-plugin-mock --timeout=180s | tail -1
helm upgrade gfd nvdp/nvidia-device-plugin --version 0.18.2 -n gpu-feature-discovery \
  -f ~/gpu/tag05/gfd-ohne-sharing.yaml --wait --timeout 180s | grep STATUS
sleep 75
kubectl get node gpu-worker2 -o json | jq -c '{alloc: .status.allocatable["nvidia.com/gpu"],
  product: .metadata.labels["nvidia.com/gpu.product"], strategy: .metadata.labels["nvidia.com/mig.strategy"]}'

Expected (shortened):

STATUS: deployed
daemonset.apps/nvidia-device-plugin-mock configured
daemon set "nvidia-device-plugin-mock" successfully rolled out
STATUS: deployed
{"alloc":"8","product":"NVIDIA-A100-SXM4-40GB","strategy":null}

kubectl apply with the manifest from Day 2 replaces the MIG DaemonSet, because both have the same name. The old MIG resources remain in the node status with capacity 0, but they do no harm.

Save your progress? Sign up for free

Clean-up

Done in the challenge.

Interview Note

  • What distinguishes MIG from time-slicing? MIG isolates compute, memory and faults in hardware; time-slicing only shares compute time, without isolation.
  • When single, when mixed? single when all instances on a node are the same size and workloads should simply request nvidia.com/gpu. mixed when different sizes are needed; then each Pod requests the matching nvidia.com/mig-… resource.
  • Why don’t 3g + 2g + 1g + 1g fit on an A100? Because 3g.20gb occupies four of the eight memory slots. It is not the sum of the sevenths that decides, but the allowed placements.

Enterprise Note

  • In production, the GPU Operator’s MIG manager manages the partitioning: a node label such as nvidia.com/mig.config=all-1g.5gb selects a profile from a ConfigMap; the manager drains the node, re-partitions and restarts the components.
  • Re-partitioning a GPU requires an empty GPU. So change MIG profiles only in a maintenance window and after kubectl drain.
  • Many platforms offer two node pools: one with whole GPUs for training, one with MIG for inference and development. Costs per team are then charged per instance.

Contents

More