Skip to content

Commit e380677

Browse files
committed
Added docs for pod-mig-partitions
1 parent f966883 commit e380677

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed
Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,69 @@
1-
# policy-pod-mig-partitions
1+
[![Kubewarden Policy Repository](https://github.com/kubewarden/community/blob/main/badges/kubewarden-policies.svg)](https://github.com/kubewarden/community/blob/main/REPOSITORIES.md#policy-scope)
2+
[![Stable](https://img.shields.io/badge/status-stable-brightgreen?style=for-the-badge)](https://github.com/kubewarden/community/blob/main/REPOSITORIES.md#stable)
23

3-
This policy guards against Pods attaching MIG Partitions without a ResourceQuota.
4+
# pod-mig-partitions
45

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.
614

715
```
816
apiVersion: policies.kubewarden.io/v1
917
kind: ClusterAdmissionPolicy
1018
metadata:
1119
name: pod-mig-partitions
1220
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
1422
rules:
1523
- apiGroups: [""]
1624
apiVersions: ["v1"]
1725
resources: ["pods"]
1826
operations: ["CREATE", "UPDATE"]
1927
settings:
20-
mutating: false # or true if your policy mutates resources
28+
mutating: false
2129
policyServer: default
2230
```
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

Comments
 (0)