Creazione e gestione dei cluster di Google Kubernetes Engine

Google Kubernetes Engine è un potente sistema di gestione e orchestrazione dei cluster per l'esecuzione dei container Docker. GKE pianifica i container nel cluster e li gestisce automaticamente in base ai requisiti che definisci (come CPU e memoria). È basato sul sistema open source Kubernetes, offrendoti la flessibilità necessaria per sfruttare l'infrastruttura cloud on-premise, ibrida o pubblica.

Leggi il riferimento agli strumenti per PowerShell per saperne di più sui cmdlet di GKE. Per saperne di più su GKE in generale, leggi la Panoramica di GKE.

Creazione e aggiornamento dei cluster GKE

Puoi creare un cluster creando prima un oggetto NodeConfig con il Cmdlet New-GkeNodeConfig. Successivamente, puoi passare l'oggetto NodeConfig al Cmdlet Add-GkeCluster. Verrà quindi creato un cluster i cui pool di nodi avranno le configurazioni impostate dall'oggetto 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"

Anziché passare l'oggetto NodeConfig, puoi anche utilizzare i parametri forniti nel cmdlet Add-GkeCluster per creare un cluster (il cmdlet creerà internamente un oggetto 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

Puoi aggiornare un cluster con il Cmdlet Set-GkeCluster. È possibile aggiornare una sola proprietà del cluster alla volta.

# 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"

Puoi elencare i cluster disponibili con il cmdlet 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"

Creazione e gestione dei pool di nodi

Un pool di nodi è un sottoinsieme di macchine all'interno di un cluster che hanno tutte la stessa configurazione. Sebbene tutti i nodi in un cluster di container siano identici, i pool di nodi consentono di creare all'interno del cluster pool di macchine con configurazioni diverse. Ad esempio, potresti creare un pool di nodi nel cluster con SSD locali o dimensioni delle istanze più grandi. Per questo motivo, i pool di nodi sono utili per personalizzare il profilo dell'istanza nel cluster.

Per aggiungere un pool di nodi al cluster, puoi prima creare un oggetto NodePool con il Cmdlet New-GkeNodePool. Puoi quindi chiamare il Cmdlet Add-GkeNodePool per aggiungere l'oggetto NodePool a un cluster.

# 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"

Puoi elencare tutti i pool di nodi in un cluster con il cmdlet Get-GkeNodePool.

# Lists all node pools in cluster "my-cluster" in the default project.
Get-GkeNodePool -ClusterName "my-cluster"

Puoi rimuovere un pool di nodi da un cluster con il cmdlet 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"