资源是什么?
k8s中所有的内容都抽象为资源,资源实例化后,叫做对象
什么叫资源清单
在k8s中,一般使用yaml格式的文件来创建符合我们预期期望的pod,这样的yaml文件,我们称为资源清单。
资源清单格式
apiVersion: group/version #指明api资源属于哪个群组和版本,同一个组可以有多个版本
kubectl api-versions #查询命令
kind: # 标记创建的资源类型
metadata: #元数据
name: #对像名称
namespace: #对象属于哪个命名空间
labels: #指定资源标签,标签是一种键值数据
spec: #定义目标资源的期望状态
kubectl explain pod #查询帮助文档
资源清单的使用
使用资源清单创建lht.yaml文件(控制端),设置CPU与mem限制
[root@server1 pod]# cat lht.yaml
apiVersion: v1
kind: Pod
metadata:
name: lht-example
spec:
#hostNetwork: true
#nodeName: server4
#imagePullSecrets:
containers:
- name: myapp
image: myapp:v1
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: "100m"
memory: "50Mi"
limits:
cpu: "200m"
memory: "100Mi"
ports:
- containerPort: 80
hostPort: 80
# - name: busybox
# image: busyboxplus:latest
# imagePullPolicy: IfNotPresent
# tty: true
# stdin: true
查看运行成功:
- kubectl describe pod lht-example
标签
kubectl get pod --show-labels #查看标签
kubectl get pod -l app #过滤包含app的标签
kubectl get pod -L app
kubectl label pod demo version=v1 #打标签
kubectl label pod demo app=nginx --overwrite #更改标签