DevOps 工程师可以使用 kubectl annotate
和 kubectl label
命令更新或删除自助命名空间注释和标签。
前提条件
过程
- 登录到主管集群。
kubectl vsphere login --server IP-ADDRESS-SUPERVISOR-CLUSTER --vsphere-username VCENTER-SSO-USERNAME
- 描述要更新的命名空间。
root@localhost [ /tmp ]# kubectl describe ns testns Name: testns Labels: my-label=test-label-2 vSphereClusterID=domain-c50 Annotations: my-ann: test-ann-2 vmware-system-namespace-owner-count: 2 vmware-system-resource-pool: resgroup-153 vmware-system-resource-pool-cpu-limit: 0.4770 vmware-system-resource-pool-memory-limit: 2000Mi vmware-system-self-service-namespace: true vmware-system-vm-folder: group-v154 Status: Active Resource Quotas Name: testns Resource Used Hard -------- --- --- requests.storage 0 5000Mi Name: testns-storagequota Resource Used Hard -------- --- --- namespace-service-storage-profile.storageclass.storage.k8s.io/requests.storage 0 9223372036854775807
- 使用 kubectl annotate 命令更新注释。
例如, kubectl annotate --overwrite ns testns my-ann="test-ann-3"要删除注释,请运行命令 kubectl annotate --overwrite ns testns my-ann-
- 使用 kubectl label 命令更新标签。
例如, kubectl label --overwrite ns testns my-label="test-label-3"要删除标签,请运行命令 kubectl label --overwrite ns testns my-label-
- 描述命名空间,查看更新。
root@localhost [ /tmp ]# kubectl describe ns testns Name: testns Labels: my-label=test-label-3 vSphereClusterID=domain-c50 Annotations: my-ann: test-ann-3 vmware-system-namespace-owner-count: 2 vmware-system-resource-pool: resgroup-153 vmware-system-resource-pool-cpu-limit: 0.4770 vmware-system-resource-pool-memory-limit: 2000Mi vmware-system-self-service-namespace: true vmware-system-vm-folder: group-v154 Status: Active Resource Quotas Name: testns Resource Used Hard -------- --- --- requests.storage 0 5000Mi Name: testns-storagequota Resource Used Hard -------- --- --- namespace-service-storage-profile.storageclass.storage.k8s.io/requests.storage 0 9223372036854775807 No LimitRange resource.