將 Kubernetes 元件新增到 Cloud Assembly 雲端範本時,您可以選擇新增叢集或讓使用者能夠在各種組態中建立命名空間。此選項通常取決於存取控制需求、設定 Kubernetes 元件的方式以及部署需求。

若要在 Cloud Assembly 中將 Kubernetes 元件新增至雲端範本,請選取設計 > 雲端範本,按一下新增,然後找到並展開左側功能表上的 Kubernetes 選項。然後,透過將所需選項 (叢集或 KBS 命名空間) 拖曳至畫布來進行選取。

將與專案相關聯的 Kubernetes 叢集新增至雲端範本,是使 Kubernetes 資源可供有效使用者使用的最簡單方法。您可以在叢集上使用標籤來控制其部署位置,如同處理其他 Cloud Assembly 資源一樣。在叢集部署的配置階段,可以使用標籤來選取區域和 VMware Tanzu Kubernetes Grid Integrated Edition (TKGI) 計劃。

一旦以這種方式新增叢集,該叢集就會自動可供所有有效的使用者使用。

雲端範本範例

第一個雲端範本範例會顯示透過標記來控制的簡單 Kubernetes 部署的範本。Kubernetes 區域是使用在 [新增 Kubernetes 區域] 頁面上設定的兩個部署計劃建立的。在此案例中,名為 placement:tag 的標籤已新增為區域上的一項功能,用於比對雲端範本上的類似限制。如果有多個區域設定了此標籤,則會選取具有最低優先順序編號的區域。

formatVersion: 1
inputs: {}
resources:
  Cluster_provisioned_from_tag:
    type: Cloud.K8S.Cluster
    properties:
      hostname: 109.129.209.125
      constraints:
	-tag: 'placement tag'
      port: 7003
      workers: 1
      connectBy: hostname 

第二個雲端範本範例顯示如何使用名為 $(input.hostname) 的變數設定範本,以便使用者能夠在請求部署時輸入所需的叢集主機名稱。在叢集部署的資源配置階段,也可以使用標籤來選取區域和 TKGI 計劃。

formatVersion: 1
inputs:
  hostname:
    type: string
    title: Cluster hostname
resources:
  Cloud_K8S_Cluster_1:
    type: Cloud.K8S.Cluster
    properties:
      hostname: ${input.hostname}
      port: 8443
      connectBy: hostname
      workers: 1

如果您想要使用命名空間來管理叢集使用率,您可以在名為 name: ${input.name} 的雲端範本中設定一個變數,以取代請求部署時使用者輸入的命名空間名稱。對於此類部署,您需要建立一個如以下範例所示的範本:

1 formatVersion: 1
2 inputs:
3 name:
4    type: string
5    title: "Namespace name"
6 resources:
7    Cloud_KBS_Namespace_1:
8        type: Cloud.KBS.Namespace
9        properties:
10            name: ${input.name}

使用者可以透過 kubeconfig 檔案來管理已部署的叢集,這些檔案可從基礎結構 > 資源 > Kubernetes 叢集頁面存取。在頁面上找到所需叢集對應的卡,然後按一下 Kubeconfig

VMware Cloud Templates 中的主管命名空間

以下是 Cloud Assembly 雲端範本中基本主管命名空間的架構。

{
  "title": "Supervisor namespace schema",
  "description": "Request schema for provisioning of Supervisor namespace resource",
  "type": "object",
  "properties": {
    "name": {
      "title": "Name",
      "description": "Alphabetic (a-z and 0-9) string with maximum length of 63 characters. The character ‘-’ is allowed anywhere except the first or last position of the identifier.",
      "type": "string",
      "pattern": "^.*\\$\\{.*\\}.*$|^((?!-)[a-z0-9-]{1,63}(?<!-))$",
      "ignoreOnUpdate": true
    },
    "description": {
      "title": "Description",
      "description": "An optional description of this Supervisor namespace.",
      "type": "string",
      "ignoreOnUpdate": true
    },
    "constraints": {
      "title": "Constraints",
      "description": "To target the correct resources, blueprint constraints are matched against infrastructure capability tags. Constraints must include the key name. Options include value, negative [!], and hard or soft requirement.",
      "type": "array",
      "recreateOnUpdate": true,
      "items": {
        "type": "object",
        "properties": {
          "tag": {
            "title": "Tag",
            "description": "Constraint definition in syntax `[!]tag_key[:tag_value][:hard|:soft]` \nExamples:\n```\n!location:eu:hard\n location:us:soft\n!pci\n```",
            "type": "string",
            "recreateOnUpdate": true
          }
        }
      }
    },
    "limits": {
      "title": "Limits",
      "description": "Defines namespace resource limits such as pods, services, etc.",
      "type": "array",
      "recreateOnUpdate": false,
      "items": {
        "type": "object",
        "properties": {
          "stateful_set_count": {
            "title": "stateful_set_count",
            "description": "This represents the new value for 'statefulSetCount' option which is the maximum number of StatefulSets in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "deployment_count": {
            "title": "deployment_count",
            "description": "This represents the new value for 'deploymentCount' option which is the maximum number of deployments in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "cpu_limit_default": {
            "title": "cpu_limit_default",
            "description": "This represents the new value for the default CPU limit (in Mhz) for containers in the pod. If specified, this limit should be at least 10 MHz.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "config_map_count": {
            "title": "config_map_count",
            "description": "This represents the new value for 'configMapCount' option which is the maximum number of ConfigMaps in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "pod_count": {
            "title": "pod_count",
            "description": "This represents the new value for 'podCount' option which is the maximum number of pods in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "job_count": {
            "title": "job_count",
            "description": "This represents the new value for 'jobCount' option which is the maximum number of jobs in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "secret_count": {
            "title": "secret_count",
            "description": "This represents the new value for 'secretCount' option which is the maximum number of secrets in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "cpu_limit": {
            "title": "cpu_limit",
            "description": "This represents the new value for 'limits.cpu' option which is equivalent to the maximum CPU limit (in MHz) across all pods in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
          "cpu_request_default": {
            "title": "cpu_request_default",
            "description": "This represents the new value for the default CPU request (in Mhz) for containers in the pod. If specified, this field should be at least 10 MHz.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "memory_limit_default": {
            "title": "memory_limit_default",
            "description": "This represents the new value for the default memory limit (in mebibytes) for containers in the pod.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "memory_limit": {
            "title": "memory_limit",
            "description": "This represents the new value for 'limits.memory' option which is equivalent to the maximum memory limit (in mebibytes) across all pods in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "memory_request_default": {
            "title": "memory_request_default",
            "description": "This represents the new value for the default memory request (in mebibytes) for containers in the pod.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "service_count": {
            "title": "service_count",
            "description": "This represents the new value for 'serviceCount' option which is the maximum number of services in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "replica_set_count": {
            "title": "replica_set_count",
            "description": "This represents the new value for 'replicaSetCount' option which is the maximum number of ReplicaSets in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "replication_controller_count": {
            "title": "replication_controller_count",
            "description": "This represents the new value for 'replicationControllerCount' option which is the maximum number of ReplicationControllers in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "storage_request_limit": {
            "title": "storage_request_limit",
            "description": "This represents the new value for 'requests.storage' which is the limit on storage requests (in mebibytes) across all persistent volume claims from pods in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "persistent_volume_claim_count": {
            "title": "persistent_volume_claim_count",
            "description": "This represents the new value for 'persistentVolumeClaimCount' option which is the maximum number of PersistentVolumeClaims in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          },
           "daemon_set_count": {
            "title": "daemon_set_count",
            "description": "This represents the new value for 'daemonSetCount' option which is the maximum number of DaemonSets in the namespace.",
            "type": "integer",
            "recreateOnUpdate": false
          }
        },
         "additionalProperties": false
      }
    }
  },
  "required": [
    "name"
  ]
}

VMware Cloud Templates 支援對主管命名空間使用限制。限制可讓您控制 CPU 和記憶體的資源使用率,以及已部署機器允許在命名空間中使用的網繭數目上限。

formatVersion: 1
inputs: {}
resources:
  Cloud_SV_Namespace_1:
    type: Cloud.SV.Namespace
    properties:
      name: '${env.deploymentName}'
      limits:
        - cpu_limit: 1000
          cpu_request_default: 800
          memory_limit: 2000
          memory_limit_default: 1500
          pod_count: 200