当前位置:网站首页>[cloud native | learn kubernetes from scratch] VIII. Namespace resource quotas and labels
[cloud native | learn kubernetes from scratch] VIII. Namespace resource quotas and labels
2022-07-25 19:56:00 【It's a bubble】
This article has been featured 《 Learn from scratch k8s》 Included

Namespaces and labels
namespacs Use case sharing
# Create a test Namespace
[[email protected] ~]# kubectl create ns test
# Delete namespace
[[email protected] ~]# kubectl delete ns test
# Switch namespace
[[email protected] ~]# kubectl config set-context --current --namespace=kube-system
[[email protected] ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
coredns-7ff77c879f-272f4 1/1 Running 3 12d
coredns-7ff77c879f-flkxx 1/1 Running 3 12d
# After switching namespaces ,kubectl get pods If you don't specify -n, What I'm looking at is kube-system Namespace resources .
# See which resources belong to namespace level If you do not specify a namespace when creating resources, it will be in the default namespace pod It's namespace level
[[email protected] ~]# kubectl api-resources --namespaced=true
namespace Resource limits
namespace It's a namespace , There are many resources in it , Then we can make a restriction on namespace resources , Prevent resources deployed by this namespace from exceeding the limit .
How to namespace What about resource limits ?
[[email protected] ~]# mkdir pp
[[email protected] ~]# cd pp
[[email protected] ~]# vim namespace-pp.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: mem-cpu-quota
namespace: test
spec:
hard:
requests.cpu: "2"
requests.memory: 2Gi
limits.cpu: "4"
limits.memory: 4Gi
Created ResourceQuota The object will be in test Add the following restrictions to the namespace :
Each container must set a memory request (memory request), Memory limit (memory limit),cpu request (cpu request) and cpu limit (cpu limit).
The total amount of memory requests for all containers must not exceed 2 GiB.
The total memory limit for all containers must not exceed 4 GiB.
Of all containers CPU The total amount requested must not exceed 2 CPU.
Of all containers CPU The total limit shall not exceed 4 CPU.
[[email protected] pp]# kubectl apply -f namespace-pp.yaml
resourcequota/mem-cpu-quota created
[[email protected] pp]# kubectl describe ns test
Name: test
Labels: <none>
Annotations: <none>
Status: Active
Resource Quotas
Name: mem-cpu-quota
Resource Used Hard
-------- --- ---
limits.cpu 0 4
limits.memory 0 4Gi
requests.cpu 0 2
requests.memory 0 2Gi
No LimitRange resource.
# establish pod Resource limits must be set when , Otherwise, the creation fails , as follows :
[[email protected] pp]# vim pod-test.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-test
namespace: test
labels:
app: tomcat-pod-test
spec:
containers:
- name: tomcat-test
ports:
- containerPort: 8080
image: tomcat
imagePullPolicy: IfNotPresent
resources:
requests:
memory: "100Mi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "2"
[[email protected] pp]# kubectl get pods -n test
NAME READY STATUS RESTARTS AGE
pod-test 1/1 Running 0 8s
[[email protected] pp]# kubectl describe pods pod-test -n test
Name: pod-test
Namespace: test
Priority: 0
Node: k8snode/192.168.11.141
Start Time: Fri, 08 Jul 2022 21:31:01 -0700
Labels: app=tomcat-pod-test
Annotations: Status: Running
IP: 10.244.2.13
IPs:
IP: 10.244.2.13
Containers:
tomcat-test:
Container ID: docker://b8604abe672c701f1ea8d027568b375989e12061090e1c5d951dae637af9b726
Image: tomcat
Image ID: docker-pullable://[email protected]:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 08 Jul 2022 21:31:02 -0700
Ready: True
Restart Count: 0
Limits:
cpu: 2
memory: 2Gi
Requests:
cpu: 500m
memory: 100Mi
Environment: <none>
Mounts:
What is a label ?
The labels are actually a pair key/value , Is associated to an object , such as Pod, In the use of tags, we tend to be able to represent the special characteristics of objects , You can see this at a glance Pod What is it , Tags can be used to divide specific objects ( Such as version , Service type, etc ), Tags can be defined directly when creating an object , It can also be modified at any time later , Each object can have multiple labels , however ,key Value must be the only . After creating tags, it is also convenient for us to group and manage resources . If the pod tagging , Then you can use the tag to view 、 Delete specified pod.
stay k8s in , Most resources can be labeled .
to pod Resource tagging
# To what already exists pod tagging Express this pod The version is v1
[[email protected] pp]# kubectl label pods pod-first release=v1
# Check whether the label is printed successfully View the specified pod
[[email protected] pp]# kubectl get pods pod-first --show-labels
It is shown as follows , The label is successful
NAME READY STATUS RESTARTS AGE LABELS
pod-first 1/1 Running 0 139m release=v1
View resource tags
# View all under the default namespace pod Tags for resources
[[email protected] pp]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx-f89759699-tc62k 1/1 Running 2 4d20h app=nginx,pod-template-hash=f89759699
nginx-test-84b997bfc5-6vccl 1/1 Running 0 16h app=nginx,pod-template-hash=84b997bfc5
nginx-test-84b997bfc5-z6lqm 1/1 Running 0 16h app=nginx,pod-template-hash=84b997bfc5
pod-first 1/1 Running 0 140m release=v1
# View the name specified under the default namespace pod All labels with
[[email protected] pp]# kubectl get pods pod-first --show-labels
NAME READY STATUS RESTARTS AGE LABELS
pod-first 1/1 Running 0 141m release=v1
# Lists the labels under the default namespace key yes release Of pod, Do not display labels
[[email protected] pp]# kubectl get pods -l release
NAME READY STATUS RESTARTS AGE
pod-first 1/1 Running 0 141m
# Lists the labels under the default namespace key yes release、 The value is v1 Of pod, Do not display labels
[[email protected] pp]# kubectl get pods -l release=v1
NAME READY STATUS RESTARTS AGE
pod-first 1/1 Running 0 142m
# Lists the labels under the default namespace key yes release All of the pod, And print the corresponding label value key As a column value Displayed in this column .
[[email protected] pp]# kubectl get pods -L release
NAME READY STATUS RESTARTS AGE RELEASE
nginx-f89759699-tc62k 1/1 Running 2 4d20h
nginx-test-84b997bfc5-6vccl 1/1 Running 0 16h
nginx-test-84b997bfc5-z6lqm 1/1 Running 0 16h
pod-first 1/1 Running 0 142m v1
# View all under all namespaces pod The label of
[[email protected] pp]# kubectl get pods --all-namespaces --show-labels
# To have release Labeled pod Display and display the corresponding key and value
[[email protected] pp]# kubectl get pods -l release=v1 -L release
NAME READY STATUS RESTARTS AGE RELEASE
pod-first 1/1 Running 0 145m v1
At the end
It's not easy to create , If you think the content will help you , Please pay attention to the third company and support me ! If there is an error , Please point out... In the comment area , I'll change it in time !
Series currently being updated : Learn from scratch k8s
Thank you for watching , The article is mixed with personal understanding , If there is any error, please contact me to point out ~
边栏推荐
- sentinel简单限流和降级demo问题记录
- Application of conductive slip ring in mechanical equipment
- Heavy! The new book "deep learning in geometry" was released, which was jointly written by imperial Institute of technology /deepmind and other figures ml Daniel. The 160 page PDF expounds the basic p
- PyTorch 模型 onnx 文件的导出和调用
- Stochastic gradient descent method, Newton method, impulse method, adagrad, rmsprop and Adam optimization process and understanding
- When the V100 of mindpole 8 card is trained to 101 epochs, an error of reading data timeout is reported
- wallys//wifi6 wifi5 router IPQ6018 IPQ4019 IPQ4029 802.11ax 802.11ac
- Error when creating dataset with mindscore
- 阿姆利塔工程学院|用于情感分析的方面术语提取中优化采样的强化主动学习方法
- Illegal mix of collations for operation ‘UNION‘(bug记录)
猜你喜欢

连接数据库警告 Establishing SSL connection without server‘s identity verification is not recommended.
![Scala foundation [set 01]](/img/6b/0f5da7ea923ef3aa436d7af9c4425c.png)
Scala foundation [set 01]

Sentinel simple current limiting and degradation demo problem record

C语言学习日记3——realloc函数

C merge set

Ml programming skills:

谷歌Pixel 6a屏下指纹扫描仪存在重大安全漏洞

Binarysearch basic binary search
![[wp]ctfshow-web入门信息搜集](/img/22/c2e5cca918800dda9df27272eb9871.png)
[wp]ctfshow-web入门信息搜集

滑雪手机端H5小游戏源码下载
随机推荐
CarSim仿真快速入门(十五)—CarSim传感器仿真之ADAS Sensor Objects (1)
tiktok手机网络环境怎么设置?tiktok怎么破播放量?
Recommended system topic | Minet: cross domain CTR prediction
UNET and mask RCNN
YOLOv7论文部分解读【含自己的理解】
Gbase 8s UDR memory management_ 02_ mi_ dalloc
一元函数积分学_分部积分法
Can you tell me whether mindspore supports torchvision Model directly uses the pre trained network, such as vgg16
统信UOS下配置安装cocos2dx开发环境
What is idealism
Configure and install cocos2dx development environment under Tongxin UOS
重磅!《几何深度学习》新书发布,帝国理工/DeepMind等图ML大牛共同撰写,160页pdf阐述几何DL基础原理和统一框架
Security Basics 4 - regular expressions
what is qml in qt
Add a subtitle of 3D effect to the container
Day7:有序二叉树(二叉搜索树)
CarSim仿真快速入门(十六)—CarSim传感器仿真之ADAS Sensor Objects (2)
从瞳代到“瞳代”再到品牌,暴利的美瞳的变与未变
Heavy! The new book "deep learning in geometry" was released, which was jointly written by imperial Institute of technology /deepmind and other figures ml Daniel. The 160 page PDF expounds the basic p
Kcon 2022 highlights and agenda revealed!