Cluster
Manages a Google Kubernetes Engine (GKE) cluster. For more information see the official documentation and the API reference.
Warning: All arguments and attributes, including basic auth username and passwords as well as certificate outputs will be stored in the raw state as plaintext. Read more about secrets in state.
Example Usage
With A Separately Managed Node Pool (Recommended)
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.serviceAccount.Account;
import com.pulumi.gcp.serviceAccount.AccountArgs;
import com.pulumi.gcp.container.Cluster;
import com.pulumi.gcp.container.ClusterArgs;
import com.pulumi.gcp.container.NodePool;
import com.pulumi.gcp.container.NodePoolArgs;
import com.pulumi.gcp.container.inputs.NodePoolNodeConfigArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var default_ = new Account("default", AccountArgs.builder()
.accountId("service-account-id")
.displayName("Service Account")
.build());
var primary = new Cluster("primary", ClusterArgs.builder()
.location("us-central1")
.removeDefaultNodePool(true)
.initialNodeCount(1)
.build());
var primaryPreemptibleNodes = new NodePool("primaryPreemptibleNodes", NodePoolArgs.builder()
.location("us-central1")
.cluster(primary.name())
.nodeCount(1)
.nodeConfig(NodePoolNodeConfigArgs.builder()
.preemptible(true)
.machineType("e2-medium")
.serviceAccount(default_.email())
.oauthScopes("https://www.googleapis.com/auth/cloud-platform")
.build())
.build());
}
}
With The Default Node Pool
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.serviceAccount.Account;
import com.pulumi.gcp.serviceAccount.AccountArgs;
import com.pulumi.gcp.container.Cluster;
import com.pulumi.gcp.container.ClusterArgs;
import com.pulumi.gcp.container.inputs.ClusterNodeConfigArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var default_ = new Account("default", AccountArgs.builder()
.accountId("service-account-id")
.displayName("Service Account")
.build());
var primary = new Cluster("primary", ClusterArgs.builder()
.location("us-central1-a")
.initialNodeCount(3)
.nodeConfig(ClusterNodeConfigArgs.builder()
.serviceAccount(default_.email())
.oauthScopes("https://www.googleapis.com/auth/cloud-platform")
.labels(Map.of("foo", "bar"))
.tags(
"foo",
"bar")
.build())
.timeouts(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference))
.build());
}
}
Autopilot
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.serviceAccount.Account;
import com.pulumi.gcp.serviceAccount.AccountArgs;
import com.pulumi.gcp.container.Cluster;
import com.pulumi.gcp.container.ClusterArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var default_ = new Account("default", AccountArgs.builder()
.accountId("service-account-id")
.displayName("Service Account")
.build());
var primary = new Cluster("primary", ClusterArgs.builder()
.enableAutopilot(true)
.location("us-central1-a")
.build());
}
}
Import
GKE clusters can be imported using the project
, location
, and name
. If the project is omitted, the default provider value will be used. Examples
$ pulumi import gcp:container/cluster:Cluster mycluster projects/my-gcp-project/locations/us-east1-a/clusters/my-cluster
$ pulumi import gcp:container/cluster:Cluster mycluster my-gcp-project/us-east1-a/my-cluster
$ pulumi import gcp:container/cluster:Cluster mycluster us-east1-a/my-cluster
For example, the following fields will show diffs if set in config- min_master_version
- remove_default_node_pool
Properties
Configuration for the Google Groups for GKE feature. Structure is documented below.
Per-cluster configuration of Node Auto-Provisioning with Cluster Autoscaler to automatically adjust the size of the cluster and create/delete node pools based on the current needs of the cluster's workload. See the guide to using Node Auto-Provisioning for more details. Structure is documented below.
Configuration for ClusterTelemetry feature, Structure is documented below.
Configuration for Confidential Nodes feature. Structure is documented below documented below.
Configuration for the Cost Allocation feature. Structure is documented below.
The default maximum number of pods per node in this cluster. This doesn't work on "routes-based" clusters, clusters that don't have IP Aliasing enabled. See the official documentation for more information.
Configuration for Using Cloud DNS for GKE. Structure is documented below.
Enable Autopilot for this cluster. Defaults to false
. Note that when this option is enabled, certain features of Standard GKE are not available. See the official documentation for available features.
) Whether FQDN Network Policy is enabled on this cluster. Users who enable this feature for existing Standard clusters must restart the GKE Dataplane V2 anetd
DaemonSet after enabling it. See the Enable FQDN Network Policy in an existing cluster for more information.
Whether to enable Cloud TPU resources in this cluster. See the official documentation.
Configuration for GKE Gateway API controller. Structure is documented below.
The number of nodes to create in this cluster's default node pool. In regional or multi-zonal clusters, this is the number of nodes per zone. Must be set if node_pool
is not set. If you're using gcp.container.NodePool
objects with no default node pool, you'll need to set this to a value of at least 1
, alongside setting remove_default_node_pool
to true
.
Configuration of cluster IP allocation for VPC-native clusters. Adding this block enables IP aliasing, making the cluster VPC-native instead of routes-based. Structure is documented below.
The location (region or zone) in which the cluster master will be created, as well as the default node location. If you specify a zone (such as us-central1-a
), the cluster will be a zonal cluster with a single cluster master. If you specify a region (such as us-west1
), the cluster will be a regional cluster with multiple masters spread across zones in the region, and with default node locations in those zones as well
The authentication information for accessing the Kubernetes master. Some values in this block are only returned by the API if your service account has permission to get credentials for your GKE cluster. If you see an unexpected diff unsetting your client cert, ensure you have the container.clusters.getCredentials
permission. Structure is documented below.
The minimum version of the master. GKE will auto-update the master to new versions, so this does not guarantee the current master version--use the read-only master_version
field to obtain that. If unset, the cluster's version will be set by GKE to the version of the most recent official release (which is not necessarily the latest version). Most users will find the gcp.container.getEngineVersions
data source useful - it indicates which versions are available. If you intend to specify versions manually, the docs describe the various acceptable formats for this field.
The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com
(Legacy Stackdriver), monitoring.googleapis.com/kubernetes
(Stackdriver Kubernetes Engine Monitoring), and none
. Defaults to monitoring.googleapis.com/kubernetes
Determines whether alias IPs or routes will be used for pod IPs in the cluster. Options are VPC_NATIVE
or ROUTES
. VPC_NATIVE
enables IP aliasing, and requires the ip_allocation_policy
block to be defined. By default, when this field is unspecified and no ip_allocation_policy
blocks are set, GKE will create a ROUTES
-based cluster.
Configuration options for the NetworkPolicy feature. Structure is documented below.
Node pool configs that apply to auto-provisioned node pools in autopilot clusters and node auto-provisioning-enabled clusters. Structure is documented below.
List of node pools associated with this cluster. See gcp.container.NodePool for schema. Warning: node pools defined inside a cluster can't be changed (or added/removed) after cluster creation without deleting and recreating the entire cluster. Unless you absolutely need the ability to say "these are the only node pools associated with this cluster", use the gcp.container.NodePool resource instead of this property.
The Kubernetes version on the nodes. Must either be unset or set to the same value as min_master_version
on create. Defaults to the default version set by GKE which is not necessarily the latest version. This only affects nodes in the default node pool. While a fuzzy version can be specified, it's recommended that you specify explicit versions as the provider will see spurious diffs when fuzzy versions are used. See the gcp.container.getEngineVersions
data source's version_prefix
field to approximate fuzzy versions. To update nodes in other node pools, use the version
attribute on the node pool.
Configuration for the cluster upgrade notifications feature. Structure is documented below.
) Configuration for the PodSecurityPolicy feature. Structure is documented below.
Configuration for private clusters, clusters with private nodes. Structure is documented below.
Configuration options for the Release channel feature, which provide more control over automatic upgrades of your GKE clusters. When updating this field, GKE imposes specific version requirements. See Selecting a new release channel for more details; the gcp.container.getEngineVersions
datasource can provide the default version for a channel. Note that removing the release_channel
field from your config will cause the provider to stop managing your cluster's release channel, but will not unenroll it. Instead, use the "UNSPECIFIED"
channel. Structure is documented below.
Configuration for the ResourceUsageExportConfig feature. Structure is documented below.
The IP address range of the Kubernetes services in this cluster, in CIDR notation (e.g. 1.2.3.4/29
). Service addresses are typically put in the last /16
from the container CIDR.
The IP address range of the Cloud TPUs in this cluster, in CIDR notation (e.g. 1.2.3.4/29
).
Workload Identity allows Kubernetes service accounts to act as a user-managed Google IAM Service Account. Structure is documented below.