$ cat priorityclass-for-gurantted.yml
---
apiVersion: v1
kind: List
items:
- apiVersion: scheduling.k8s.io/v1beta1
kind: PriorityClass
metadata:
name: guaranteed
value: 900000000
globalDefault: false
description: "priority for guaranteed pod"
- apiVersion: scheduling.k8s.io/v1beta1
kind: PriorityClass
metadata:
name: bustable
value: 1000
globalDefault: false
description: "priority for bustable pod"
# create
$ kc create -f priorityclass-for-quota.yaml
priorityclass.scheduling.k8s.io/guranteed created
priorityclass.scheduling.k8s.io/bustable created
$ kc get priorityclass
NAME VALUE GLOBAL-DEFAULT AGE
bustable 1000 false 2s
guaranteed 900000000 false 2s
system-cluster-critical 2000000000 false 23d
system-node-critical 2000001000 false 23d
apiVersion: v1
kind: Pod
metadata:
name: guaranteed-priority
namespace: test-quota1
spec:
containers:
- name: ubuntu
image: ubuntu
command: ["/bin/sh"]
args: ["-c", "while true; do echo hello; sleep 10;done"]
resources:
requests:
memory: "500Mi"
cpu: "500m"
limits:
memory: "500Mi"
cpu: "500m"
priorityClassName: guaranteed
# namespace and quota per priorityclass
$ cat namespace-quota.yaml
---
apiVersion: v1
kind: Namespace
metadata:
name: test-quota1
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: ResourceQuota
metadata:
name: pods-guaranteed
namespace: test-quota1
spec:
hard:
cpu: "10"
memory: 10Gi
pods: "20"
scopeSelector:
matchExpressions:
- operator : In
scopeName: PriorityClass
values: ["guaranteed"]
- apiVersion: v1
kind: ResourceQuota
metadata:
name: pods-bustable
namespace: test-quota1
spec:
hard:
cpu: "10"
memory: 10Gi
scopeSelector:
matchExpressions:
- operator : In
scopeName: PriorityClass
values: ["bustable"]
# deployment for guaranteed
$ cat test-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment-on-guaranteed
namespace: test-quota1
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
resources:
requests:
cpu: "500m"
memory: "500Mi"
limits:
cpu: "500m"
memory: "500Mi"
priorityClassName: guaranteed
# deployment for bustable
$ cat test-deployment-bustable.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment-on-bustable
namespace: test-quota1
labels:
app: nginx2
spec:
replicas: 3
selector:
matchLabels:
app: nginx2
template:
metadata:
labels:
app: nginx2
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
resources:
requests:
cpu: "1000m"
memory: "1Gi"
priorityClassName: bustable
$ kc create -f namespace-quota.yaml
$ kc create -f test-deployment-guaranteed.yaml
$ kc create -f test-deployment-bustable.yaml
$ kc describe quota -n test-quota1
Name: pods-bustable
Namespace: test-quota1
Resource Used Hard
-------- ---- ----
cpu 3 10
memory 3Gi 10Gi
#-> bustable pod 3개 잡힘
Name: pods-guaranteed
Namespace: test-quota1
Resource Used Hard
-------- ---- ----
cpu 1500m 10
memory 1500Mi 10Gi
pods 3 20
#-> guaranteed pod 3개 잡힘
$ kc get deployment,pod -n test-quota1
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.extensions/nginx-deployment-on-bustable 3/3 3 3 31s
deployment.extensions/nginx-deployment-on-guaranteed 3/3 3 3 10m
NAME READY STATUS RESTARTS AGE
pod/nginx-deployment-on-bustable-5cc9d55957-89jmt 1/1 Running 0 31s
pod/nginx-deployment-on-bustable-5cc9d55957-q7q6d 1/1 Running 0 31s
pod/nginx-deployment-on-bustable-5cc9d55957-tj42g 1/1 Running 0 31s
pod/nginx-deployment-on-guaranteed-768b9dbd59-hsgf2 1/1 Running 0 10m
pod/nginx-deployment-on-guaranteed-768b9dbd59-lj4hp 1/1 Running 0 10m
pod/nginx-deployment-on-guaranteed-768b9dbd59-ms2dp 1/1 Running 0 10m
# pod 상태 확인
## guaranteed
$ kc get pod/nginx-deployment-on-guaranteed-768b9dbd59-hsgf2 -n test-quota1 -o yaml
apiVersion: v1
kind: Pod
metadata:
...
spec:
...
priority: 900000000
priorityClassName: guaranteed
...
status:
...
qosClass: Guaranteed
## bustable
$ kc get pod/nginx-deployment-on-bustable-5cc9d55957-q7q6d -n test-quota1 -o yaml
apiVersion: v1
kind: Pod
metadata:
...
spec:
...
priority: 1000
priorityClassName: bustable
...
status:
...
qosClass: Burstable