Membuat dan mengelola cluster Google Kubernetes Engine

Google Kubernetes Engine adalah pengelola cluster dan sistem orkestrasi yang canggih untuk menjalankan container Docker Anda. GKE menjadwalkan container Anda ke dalam cluster dan mengelolanya secara otomatis berdasarkan persyaratan yang Anda tentukan (seperti CPU dan memori). Layanan ini dibangun di sistem Kubernetes open source, sehingga memberi Anda fleksibilitas untuk memanfaatkan infrastruktur lokal, hybrid, atau cloud publik.

Baca referensi Tools for PowerShell untuk mempelajari lebih lanjut cmdlet GKE. Untuk mempelajari lebih lanjut GKE secara umum, baca Ringkasan GKE.

Membuat dan memperbarui cluster GKE

Anda dapat membuat cluster dengan terlebih dahulu membuat objek NodeConfig dengan cmdlet New-GkeNodeConfig. Setelah itu, Anda dapat meneruskan objek NodeConfig ke cmdlet Add-GkeCluster. Kemudian, cluster akan dibuat dengan konfigurasi node pool yang ditetapkan dari objek 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"

Daripada meneruskan objek NodeConfig, Anda juga dapat menggunakan parameter yang disediakan di cmdlet Add-GkeCluster untuk membuat cluster (objek NodeConfig akan dibuat secara internal oleh cmdlet).

# 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

Anda dapat mengupdate cluster dengan cmdlet Set-GkeCluster. Hanya satu properti cluster yang dapat diupdate dalam satu waktu.

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

Anda dapat membuat daftar cluster yang tersedia dengan 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"

Membuat dan Mengelola Node Pool

Node pool adalah subset mesin dalam cluster yang semuanya memiliki konfigurasi yang sama. Meskipun semua node dalam cluster penampung identik, kumpulan node memungkinkan Anda membuat kumpulan mesin dalam cluster yang memiliki konfigurasi berbeda. Misalnya, Anda dapat membuat kumpulan node di cluster yang memiliki SSD lokal atau ukuran instance yang lebih besar. Oleh karena itu, node pool berguna untuk menyesuaikan profil instance di cluster Anda.

Untuk menambahkan node pool ke cluster, Anda dapat membuat objek NodePool terlebih dahulu dengan cmdlet New-GkeNodePool. Kemudian, Anda dapat memanggil cmdlet Add-GkeNodePool untuk menambahkan objek NodePool ke 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"

Anda dapat mencantumkan semua node pool dalam cluster dengan cmdlet Get-GkeNodePool.

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

Anda dapat menghapus node pool dari cluster dengan 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"