Label Meaning

Labels are actually a pair of key/value, which are associated with objects, such as Pods. We tend to use labels to indicate the special characteristics of objects. The value of Labels has no meaning to the system itself, but only makes sense to users. The key of the labels attribute of the same resource object must be unique, and the label can be attached to various resource objects, such as Node, Pod, Service, RC, etc. A resource has multiple tags, which can realize management in different dimensions. The composition of the label: key=value. Label can be attached to the object when it is created, or it can be added or modified through the API after the object is created

Label naming convention

label must start with a letter or number, letters, numbers, hyphens, dots and underscores can be used, and the maximum length is 63 characters

Reasons for using Label

-When there are more and more resources of the same type, it is necessary to divide and manage the resources. At this time, you can use Label to name the resource objects to facilitate configuration, deployment and other management tasks, and improve the efficiency of resource management. The label function is similar to the Java package, which can manage different files separately, making the whole more organized and conducive to maintenance.

-Use Label to reference objects

Label use

  1. Command creation

    label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]
  2. The kubectl get pods command will not list any labels by default, use the --show-labels option to view

    kubectl get pods --show-labels
  3. View by designated label

    kubectl get pods -L creation_method,env
  4. View the nodes that match the label conditions

    kubectl get nodes -l label key=label values
    kubectl get nodes -l app=tomcat
  5. View pods that match the tag key

    kubectl get pods -L app
  6. Add label app=tomcat to the Pod named tomcat

    kubectl label pods tomcat app=tomcat
  7. Change the label of the Pod named tomcat to app=tomcat1, and overwrite the existing value

    kubectl label --overwrite pods tomcat app=tomcat1
  8. Add labels to all pods in the namespace

    kubectl label pods --all test=test
  9. Delete the label named app. (Use - minus sign to connect)

    kubectl label pods tomcat app-
  10. yaml create label
    Added two labels to tomcat's Pod, namely app:tomcat and release:tomcat

    apiVersion: v1
    kind: Pod
    metadata:
    name: tomcat
    labels:
     app: tomcat
     release: stable
    spec:
    containers:
    -name: tomcat
     image: tomcat
     ports:
     -containerPort: 80

Label commonly used multi-dimensional label classification

-Version label (release): stable (stable version), canary (canary version), beta (beta)

-Environment (environment): dev (development), qa (test), production (production), op (operation and maintenance)

-Application (applaction): ui (design), as (application software), pc (computer side), sc (network aspect)

-Architecture layer (tier): frontend (front end), backend (back end), cache (cache)

-Partition label (partition): customerA (customer), customerB

-Quality control level (track): daily (every day), weekly (weekly)

apiVersion: v1
kind: Pod
metadata:
  name: label-pod-test
  labels: #Use the labels field to define labels, you can define multiple labels at a time, here define 3 labels
    release: stable #Version: stable version
    env: qa #Environment: Test
    tier: frontend #Architecture class: frontend
spec:
  containers:
  -name: testTomcatLabel
    image: tomcat #Deployed tomcat service
点赞(1)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部