当前位置:网站首页>[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 ~
边栏推荐
猜你喜欢

Hongke shares | how to solve blackmail software security vulnerabilities

binarySearch基础二分查找

Authorized wireless communication standard

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

Rainbow plug-in extension: monitor MySQL based on MySQL exporter
![[wp]ctfshow-web入门信息搜集](/img/22/c2e5cca918800dda9df27272eb9871.png)
[wp]ctfshow-web入门信息搜集

Introduction to web security ICMP testing and defense

Add a subtitle of 3D effect to the container

【神器】截图+贴图工具 Snipaste

IP地址的概念
随机推荐
[wp]ctfshow-web introductory information collection
SDL text display
wallys//wifi6 wifi5 router IPQ6018 IPQ4019 IPQ4029 802.11ax 802.11ac
[wp]ctfshow-web getting started - Explosion
Wechat applet 10 - wechat template
What is the method to load the torch pre trained model for the mindspore model finetune?
Split very long line of words into separate lines of max length
Binarysearch basic binary search
统信UOS下配置安装cocos2dx开发环境
加州大学|用于未指定环境的可行对抗鲁棒强化学习
NPM semantic version control, solution console prop being mutated: "placement" error
PyTorch 模型 onnx 文件的导出和调用
Introduction to web security ICMP testing and defense
Error when creating dataset with mindscore
When the V100 of mindpole 8 card is trained to 101 epochs, an error of reading data timeout is reported
Hongke shares | how to solve blackmail software security vulnerabilities
YOLOv7论文部分解读【含自己的理解】
六轴传感器使用学习记录
推荐系统专题 | MiNet:跨域CTR预测
C merge set