当前位置:网站首页>Resourcequota for detailed explanation of kubernetes resource constraints
Resourcequota for detailed explanation of kubernetes resource constraints
2022-06-24 05:26:00 【Honest1y】
1 brief introduction
Kubernetes There are two ways to limit resources :ResourceQuota and LimitRange.
among ResourceQuota Is aimed at namespace Do resource constraints , and LimitRange Is aimed at namespace Resource constraints for each component in .
When more than one namespace When sharing the same cluster, there may be one namespace The resource quota used exceeds its fair quota , Lead to other namespace Of resources are occupied . At this time, we can work for each namespace Create a ResourceQuota,
The user is in namespace When creating resources in ,quota The quota system tracks usage , To make sure it doesn't exceed ResourceQuota The limit value of . If creating or updating resources violates quota constraints , be HTTP The status code will cause the request to fail 403 FORBIDDEN. The change of resource quota will not affect the pod.
apiserver The startup parameters for are usually kubernetes Enabled by default ResourceQuota, stay apiserver Start parameter of –enable-admission-plugins= If any ResourceQuota Start .
2 Use
Create a test using NS
[~] kubectl create ns testquota namespace/testquota created
[~] kubectl get ns | grep quota testquota Active 3m41s
Create a ResourceQuota
[yaml] cat resourcequota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: testquota-resources
namespace: testquota
spec:
hard:
pods: "4"
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi[yaml] kubectl apply -f resourcequota.yaml resourcequota/testquota-resources created
[yaml] kubectl describe resourcequotas -n testquota testquota-resources Name: testquota-resources Namespace: testquota Resource Used Hard -------- ---- ---- limits.cpu 0 2 limits.memory 0 2Gi pods 0 4 requests.cpu 0 1 requests.memory 0 1Gi
Create a Deployment And limit resources
[yaml] cat quota-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: testquota
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
resources:
requests:
memory: "100Mi"
cpu: "100m"
limits:
memory: "200Mi"
cpu: "500m"
[yaml] kubectl apply -f quota-deploy.yaml
deployment.apps/nginx-deployment created
[yaml] kubectl get po -n testquota
NAME READY STATUS RESTARTS AGE
nginx-deployment-7c6bbc77d8-mfxnl 1/1 Running 0 9smodify deployment replications , Make the total resources used exceed ResourceQuota Resources defined in
First, check the current resource usage
[yaml] kubectl describe resourcequotas -n testquota testquota-resources Name: testquota-resources Namespace: testquota Resource Used Hard -------- ---- ---- limits.cpu 500m 2 limits.memory 200Mi 2Gi pods 1 4 requests.cpu 100m 1 requests.memory 100Mi 1Gi
Number of modified copies
[yaml] kubectl scale deployment -n testquota nginx-deployment --replicas=4 deployment.apps/nginx-deployment scaled [yaml] kubectl get po -n testquota NAME READY STATUS RESTARTS AGE nginx-deployment-7c6bbc77d8-5mbc6 1/1 Running 0 7s nginx-deployment-7c6bbc77d8-ld69h 1/1 Running 0 7s nginx-deployment-7c6bbc77d8-mfxnl 1/1 Running 0 5m18s nginx-deployment-7c6bbc77d8-sdcxb 1/1 Running 0 7s
Current resource usage
[yaml] kubectl describe resourcequotas -n testquota testquota-resources Name: testquota-resources Namespace: testquota Resource Used Hard -------- ---- ---- limits.cpu 2 2 limits.memory 800Mi 2Gi pods 4 4 requests.cpu 400m 1 requests.memory 400Mi 1Gi
Create another deployment
[yaml] kubectl apply -f quota-deploy-2.yaml deployment.apps/nginx2-deployment created [yaml] kubectl get deployment -n testquota NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment 4/4 4 4 7m48s nginx2-deployment 0/1 0 0 34s
You can see , although deployment Created successfully , But the corresponding pod, You can see deployment Report errors
[yaml] kubectl describe deployments -n testquota nginx2-deployment Name: nginx2-deployment Namespace: testquota ... Replicas: 1 desired | 0 updated | 0 total | 0 available | 1 unavailable NewReplicaSet: nginx2-deployment-7c6bbc77d8 (0/1 replicas created) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ScalingReplicaSet 98s deployment-controller Scaled up replica set nginx2-deployment-7c6bbc77d8 to 1
It can be seen that this is due to the pod The sum of has exceeded namespace Cannot create due to the total resource limit pod.
3 Common resource types
边栏推荐
- What domain name is gov? What should I pay attention to when applying for a domain name?
- What is a company domain name? What should I pay attention to when registering a company domain name?
- PXE introduction and use
- What is the implementation of domain name to IP address conversion? What are the benefits of switching to a website?
- What is the domain name of Org? Why do I need domain name resolution
- The 2021 smart Expo is about to open. Tencent Youtu and "Ai Gallery" will "Chongqing" with you
- What is a domain name server? What are the types of domain name servers?
- Fluent version control FVM
- What is the domain name of the website? What problems should be paid attention to when applying for a domain name
- Flutter common development problems
猜你喜欢

Hard core observation 553 AI needs to identify almost everyone in the world with hundreds of billions of photos

Answer questions! This article explains the automated testing framework in software testing from beginning to end
What cloud native knowledge should programmers master?

How does win10 turn off f1~f12 shortcut keys?

Intensive learning and application of "glory of the king" to complete the application of 7 real worlds other than human players
Easy to understand JDBC tutorial - absolutely suitable for zero Foundation

How should we learn cloud native in 2022?
![[leetcode daily question] push domino](/img/81/1c31e97d9a245816514bcf47c92107.jpg)
[leetcode daily question] push domino
Learning routes and materials for cloud native O & M engineers
随机推荐
What is a top-level domain name? What are the classifications of a top-level domain name
What is the implementation of domain name to IP address conversion? What are the benefits of switching to a website?
How to register a domain name how to make the domain name short and easy to remember
PTA 1066 image filtering (15 points)
How does the mobile phone remotely connect to the ECS? What should be paid attention to during the operation
Lightweight toss plan 3, develop in the browser - build your own development bucket (Part 2)
Open source and SaaS, how to choose software?
[leetcode daily question] push domino
Have you got the programmer's drawing tools and skills?
Technical dry goods | understand go memory allocation
PTA 1046 stroke (15 points)
Bert series Roberta Albert erine detailed explanation and use learning notes
Spirit breath development log (9)
What domain name is gov? What should I pay attention to when applying for a domain name?
[jest] summary of the use of automated test jest
Tencent conference rest API x-tc-registered parameter policy update notification
What is domain name registration? Do you still need to purchase ECS after domain name registration?
When a beef cow has an "electronic ID card"
What is domain name resolution? How much does domain name registration cost
What is required for domain name filing and how to select an enterprise domain name