Google Kubernetes Engine 是功能強大的叢集管理器和自動化調度管理系統,可用於執行 Docker 容器。GKE 可將容器排入叢集中,並根據設定的需求 (例如 CPU 和記憶體) 自動加以管理。這套產品採用開放原始碼的 Kubernetes 系統,讓您在使用內部雲端、混合式雲端或公用雲端基礎架構時能兼顧彈性。
如要進一步瞭解 GKE 指令碼,請參閱 Tools for PowerShell 參考資料。如要進一步瞭解 GKE 的一般資訊,請參閱 GKE 總覽。
建立及更新 GKE 叢集
您可以先使用 New-GkeNodeConfig
指令建立 NodeConfig
物件,以此方式建立叢集。之後就可直接將 NodeConfig
物件傳入 Add-GkeCluster
指令碼。如此即會建立一個叢集,其節點集區是根據 NodeConfig
物件設定。
# Creates a GKE Node Config with image type CONTAINER_VM # and 20 GB disk size for each node. $nodeConfig = New-GkeNodeConfig -DiskSizeGb 20 ` -ImageType CONTAINER_VM # Creates a cluster named "my-cluster" in the default zone of the # default project using config $nodeConfig and network "my-network". Add-GkeCluster -NodeConfig $nodeConfig ` -ClusterName "my-cluster" ` -Network "my-network"
除了直接將 NodeConfig
物件傳入之外,也可以使用 Add-GkeCluster
cmdlet 所提供的參數來建立叢集 (cmdlet 會在內部建立 NodeConfig
物件)。
# Creates a cluster named "my-cluster" with description "my new cluster" # in the default zone of the default project using machine type # "n1-standard-4" for each Compute Engine in the cluster. # The cluster will use the subnetwork "my-subnetwork". # The cluster's nodes will have autoupgrade enabled. # The cluster will also autoscale its node pool to a maximum of 2 nodes. Add-GkeCluster -MachineType "n1-standard-4" ` -ClusterName "my-cluster" ` -Description "My new cluster" ` -Subnetwork "my-subnetwork" ` -EnableAutoUpgrade ` -MaximumNodesToScaleTo 2
您可以使用 Set-GkeCluster
指令更新叢集,一次只能更新叢集的一個屬性。
# Sets additional zones of cluster "my-cluster" in zone "asia-east1-a"
# to zones "asia-east1-b" and "asia-east1-c". This means the clusters will
# have nodes created in these zones. The primary zone
# ("asia-east1-a" in this case) will be added to the
# AdditionalZone
array by the cmdlet.
Set-GkeCluster -ClusterName "my-cluster" `
-Zone "asia-east1-a" `
-AdditionalZone "asia-east1-b", "asia-east1-c"
您可以使用 Get-GkeCluster
指令列出可用的叢集。
# Lists all container clusters in the default project. Get-GkeCluster # List all container clusters in zone "us-central1-a" # of the default project. Get-GkeCluster -Zone "us-central1-a"
建立及維護節點集區
節點集區是同屬於一個叢集,且具有相同設定的機器群組。雖然容器叢集中的所有節點都相同,但節點集區允許在叢集中建立具有不同設定的機器集區。舉例來說,您可以在叢集中建立具有本機 SSD 或執行個體大小更大的節點集區。因此,節點集區可用於自訂叢集中的執行個體資料。
如要在叢集中新增節點集區,可先用 New-GkeNodePool
指令碼建立 NodePool
物件。然後呼叫 Add-GkeNodePool
cmdlet,在叢集中新增 NodePool
物件。
# Creates a node pool named "my-nodepool" with image type # CONTAINER_VM for each node. $nodePool = New-GkeNodePool -NodePoolName "my-nodepool" ` -ImageType CONTAINER_VM # Adds the pool to cluster "my-cluster". Add-GkeNodePool -NodePool $nodePool -Cluster "my-cluster"
您可以使用 Get-GkeNodePool
指令列出叢集中的所有節點集區。
# Lists all node pools in cluster "my-cluster" in the default project. Get-GkeNodePool -ClusterName "my-cluster"
您可以使用 Remove-GkeCluster
指令碼,從叢集中移除節點集區。
# Removes the node pool "my-nodepool" in cluster "my-cluster" # in the zone "us-west1-b" of the default project. Remove-GkeCluster -ClusterName "my-cluster" ` -Zone "us-west1-b" ` -NodePoolName "my-nodepool"