Skip to content

Instantly share code, notes, and snippets.

@amcginlay
Last active February 9, 2021 22:43
Show Gist options
  • Select an option

  • Save amcginlay/e3edd0a060ac3588060c372094846488 to your computer and use it in GitHub Desktop.

Select an option

Save amcginlay/e3edd0a060ac3588060c372094846488 to your computer and use it in GitHub Desktop.
# the following will demonstrate how combined CPU requirements
# can stop a pod from being scheduled inside a given namespace
# create the manifest.yaml file shown below
# note the pod, named combo, is built from a pair of containers (nginx and redis)
cat > ./manifest.yaml << EOF
apiVersion: v1
kind: Namespace
metadata:
name: rqtest
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: rqtest
namespace: rqtest
spec:
hard:
requests.cpu: 1
requests.memory: 1Gi
limits.cpu: 2
limits.memory: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: combo
name: combo
namespace: rqtest
spec:
replicas: 1
selector:
matchLabels:
app: combo
template:
metadata:
creationTimestamp: null
labels:
app: combo
spec:
containers:
- image: nginx
name: nginx
resources:
requests:
cpu: 550m
memory: 500Mi
limits:
cpu: 600m
memory: 600Mi
- image: redis
name: redis
resources:
requests:
cpu: 500m
memory: 500Mi
limits:
cpu: 600m
memory: 600Mi
EOF
# create the resources and observe how the pod is not scheduled
kubectl apply -f manifest.yaml
kubectl get all -k rqtest
# why is this?
# the requests.cpu setting inside the nginx container is 550m (NOTE: slightly oversized!)
# the requests.cpu setting inside the redis container is 500m
# 550m+500m exceeds the hard "requests.cpu: 1" setting in the ResourceQuota object for the namespace
# slim down the nginx requests.cpu setting ...
sed -i "s/550/500/g" manifest.yaml
# ... and try again to see the pod getting scheduled
kubectl apply -f manifest.yaml
kubectl get all -n rqtest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment