|
1 | | -# policy-pod-mig-partitions |
| 1 | +[](https://github.com/kubewarden/community/blob/main/REPOSITORIES.md#policy-scope) |
| 2 | +[](https://github.com/kubewarden/community/blob/main/REPOSITORIES.md#stable) |
2 | 3 |
|
3 | | -This policy guards against Pods attaching MIG Partitions without a ResourceQuota. |
| 4 | +# pod-mig-partitions |
4 | 5 |
|
5 | | -**Example policy:** |
| 6 | +This project is meant to work with [NVIDIA GPU Operator](https://github.com/NVIDIA/gpu-operator). |
| 7 | + |
| 8 | +With the NVIDIA GPU Operator, pods request MIG partitions with resource requests. |
| 9 | +This policy ensures that a pod can only request a MIG partition within a namespace's [ResourceQuota](https://kubernetes.io/docs/concepts/policy/resource-quotas/). |
| 10 | + |
| 11 | +## Example |
| 12 | + |
| 13 | +The policy doesn't require any configuration, so you just need to add it to a Kubewarden policy server. |
6 | 14 |
|
7 | 15 | ``` |
8 | 16 | apiVersion: policies.kubewarden.io/v1 |
9 | 17 | kind: ClusterAdmissionPolicy |
10 | 18 | metadata: |
11 | 19 | name: pod-mig-partitions |
12 | 20 | spec: |
13 | | - module: harbor.op-prg2-0-dev-ingress.op.suse.org/policy-pod-mig-partitions/policy-pod-mig-partitions:0.1.0 |
| 21 | + module: registry://ghcr.io/suse/openplatform-kubewarden-policies/rke2-mig-partitions:latest |
14 | 22 | rules: |
15 | 23 | - apiGroups: [""] |
16 | 24 | apiVersions: ["v1"] |
17 | 25 | resources: ["pods"] |
18 | 26 | operations: ["CREATE", "UPDATE"] |
19 | 27 | settings: |
20 | | - mutating: false # or true if your policy mutates resources |
| 28 | + mutating: false |
21 | 29 | policyServer: default |
22 | 30 | ``` |
| 31 | + |
| 32 | +With the policy active, if a pod tried to create or update a pod, adding a MIG partition, this policy should deny the change. |
| 33 | + |
| 34 | +```yaml |
| 35 | +apiVersion: v1 |
| 36 | +kind: Pod |
| 37 | +metadata: |
| 38 | + name: ollama |
| 39 | +spec: |
| 40 | + containers: |
| 41 | + - image: dp.apps.rancher.io/containers/ollama:latest |
| 42 | + name: ollama |
| 43 | + resources: |
| 44 | + limits: |
| 45 | + cpu: '8' |
| 46 | + memory: 32Gi |
| 47 | + nvidia.com/mig-1g.12gb: '1' |
| 48 | + requests: |
| 49 | + cpu: '8' |
| 50 | + memory: 32Gi |
| 51 | + nvidia.com/mig-1g.12gb: '1' |
| 52 | +``` |
| 53 | +
|
| 54 | +To get the pod to deploy, would need to add a ResourceQuota with the requested resource. |
| 55 | +
|
| 56 | +```yaml |
| 57 | +apiVersion: v1 |
| 58 | +kind: ResourceQuota |
| 59 | +metadata: |
| 60 | + name: gpu-quota |
| 61 | +spec: |
| 62 | + hard: |
| 63 | + requests.nvidia.com/mig-1g.12gb: '1' |
| 64 | +``` |
| 65 | +
|
| 66 | +Now, if the above pod requests the same MIG partition, it should be allowed. The pod-mig-partitions policy will see that `nvidia.com/mig-1g.12gb` is in the namespace's ResourceQuota and allow the change. |
| 67 | +If the pod instead requests `requests.nvidia.com/mig-2g.24gb`, the policy would deny the change because that MIG partition is not in the ResourceQuota. |
| 68 | +However, the policy doesn't concern itself with how many MIG partitions are in the request, instead, |
| 69 | +Kubernetes ensures that the Pod doesn't exceed the namespace's ResourceQuotas. |
0 commit comments