跳到主要内容

Kubernetes 标签

节点标签

  • kubernetes.io/ingress.class
labeldemodesc
k3s.io/hostnamenode-3
k3s.io/internal-ip10.10.1.1
kubernetes.io/archamd64+v1.14
kubernetes.io/hostnamenode-3
kubernetes.io/oslinux+v1.14
node-role.kubernetes.io/<role>true
node-role.kubernetes.io/mastertrueMaster node
node-role.kubernetes.io/control-planetruecp
node.kubernetes.io/instance-typek3s
topology.kubernetes.io/region+v1.17
topology.kubernetes.io/zone+v1.17
# 设置 node role 为 worker
# role 名字任意
# value 不重要,主要是存在该 label
kubectl label node node-2 node-role.kubernetes.io/worker=true
# 规划 region 和 zone
kubectl label node master-1 topology.kubernetes.io/region=sh
kubectl label node master-1 topology.kubernetes.io/zone=sh-dc1

Deprecated

labeldemodesc
beta.kubernetes.io/archamd64!v1.14, -v1.18
beta.kubernetes.io/instance-typek3s!v1.17
beta.kubernetes.io/oslinux!v1.14, -v1.18
failure-domain.beta.kubernetes.io/region!v1.17
failure-domain.beta.kubernetes.io/zone!v1.17

资源标签

kindannotationdemodesc
StorageClassstorageclass.kubernetes.io/is-default-classtrue默认 StorageClass
VolumeSnapshotClasssnapshot.storage.kubernetes.io/is-default-classtrue
Ingresskubernetes.io/ingress.classnginx废弃,spec.ingressClassName
IngressClassingressclass.kubernetes.io/is-default-classtrue
kindlabeldemodesc
Namespacekubernetes.io/metadata.namekube-systemnamespace 的名字
kubectl get storageclass

# 取消 sc 的默认值
kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
# 设置默认
kubectl patch storageclass longhorn -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

应用标签

labelexample
app.kubernetes.io/namemysql
app.kubernetes.io/instancemysql-abcd
app.kubernetes.io/version5.7
app.kubernetes.io/componentdatabase
app.kubernetes.io/part-ofghost
app.kubernetes.io/managed-byhelm
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/component: prometheus
app.kubernetes.io/instance: kube-prometheus
app.kubernetes.io/name: kube-prometheus
topologyKey: kubernetes.io/hostname

Helm 标签

labelexample
app.kubernetes.io/managed-byHelm
# 资源 label
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/version: 0.35.0
helm.sh/chart: ingress-nginx-2.16.0

# selector label
matchLabels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx

Helm 注解

annotationvaluedesc
meta.helm.sh/release-namelinkerd2
meta.helm.sh/release-namespacelinkerd

LabelSelector

  • labelSelector - 数组内为 OR 关系
  • matchLabels
    • label: value
  • matchExpressions - 数组内为 AND 关系
    • key
    • operator: In, NotIn, Exists, DoesNotExist
    • values: []
dashboardLabelSelector: # OR
- matchExpressions: # AND
- { key: app, operator: In, values: [grafana] }
- { key: group, operator: In, values: [grafana] }

FAQ

region vs zone