身為 DevOps 工程師,您可以使用 kubectl annotatekubectl label 命令來更新或刪除自助服務命名空間註解和標籤。

必要條件

確認您具有要更新的命名空間的擁有者權限。

程序

  1. 登入主管叢集。
    kubectl vsphere login --server IP-ADDRESS-SUPERVISOR-CLUSTER --vsphere-username VCENTER-SSO-USERNAME
  2. 說明要更新的命名空間。
    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
  3. 使用 kubectl annotate 命令更新註解。
    例如, kubectl annotate --overwrite ns testns my-ann="test-ann-3"
    若要刪除註解,請執行命令 kubectl annotate --overwrite ns testns my-ann-
  4. 使用 kubectl label 命令更新標籤。
    例如, kubectl label --overwrite ns testns my-label="test-label-3"
    若要刪除標籤,請執行命令 kubectl label --overwrite ns testns my-label-
  5. 說明要查看更新的命名空間。
    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.