In this article, I will send a link to any mirror I use for you to download and learn!
yaml please download to my github to learn!
github: https://github.com/heyangguang
If you have any questions, please contact my Email directly: heyangev@cn.ibm.com.
Labels official website
https://kubernetes.io/docs/co...
Labels introduction
Literally, it means labeling our different Pod s or Controller s to achieve the following functions:
- Indicator meta-information
- Controller and Service can control Pod life cycle through label selector
- Impacts on Scheduling
Lables view
[root@master01 ~]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS master01 Ready master 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/master= node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work= node02 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,node-role.kubernetes.io/work=
Lables creation
Keep in mind that the tag format is < Key: Value > and that Key must be unique for a given value.
1. Use yaml to create labels for Pod
[root@master01 ~]# cat pod-labels.yaml apiVersion: v1 kind: Pod metadata: name: label-demo labels: environment: production app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 [root@master01 ~]# kubectl apply -f pod-labels.yaml pod/label-demo created [root@master01 ~]# kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS label-demo 1/1 Running 0 65s app=nginx,environment=production
2. Create tags from the command line
[root@master01 ~]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS master01 Ready master 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/master= node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work= node02 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,node-role.kubernetes.io/work= [root@master01 ~]# kubectl label nodes node01 disktype=ssd node/node01 labeled [root@master01 ~]# kubectl get nodes node01 --show-labels NAME STATUS ROLES AGE VERSION LABELS node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work=
Lables delete
[root@master01 ~]# kubectl label nodes node01 disktype- node/node01 labeled [root@master01 ~]# kubectl get nodes node01 --show-labels NAME STATUS ROLES AGE VERSION LABELS node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work=