Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Terraform module for configuring GKE clusters.

License

NotificationsYou must be signed in to change notification settings

gajicdev/terraform-google-kubernetes-engine

 
 

Repository files navigation

This module handles opinionated Google Cloud Platform Kubernetes Engine cluster creation and configuration with Node Pools, IP MASQ, Network Policy, etc.The resources/services/activations/deletions that this module will create/trigger are:

  • Create a GKE cluster with the provided addons
  • Create GKE Node Pool(s) with provided configuration and attach to cluster
  • Replace the default kube-dns configmap ifstub_domains are provided
  • Activate network policy ifnetwork_policy is true
  • Addip-masq-agent configmap with providednon_masquerade_cidrs ifconfigure_ip_masq is true

Sub modules are provided for creating private clusters, beta private clusters, and beta public clusters as well. Beta sub modules allow for the use of various GKE beta features. See the modules directory for the various sub modules.

Compatibility

This module is meant for use with Terraform 0.12. If you haven'tupgraded and need a Terraform0.11.x-compatible version of this module, the last released versionintended for Terraform 0.11.x is3.0.0.

Usage

There are multiple examples included in theexamples folder but simple usage is as follows:

module"gke" {source="terraform-google-modules/kubernetes-engine/google"project_id="<PROJECT ID>"name="gke-test-1"region="us-central1"zones=["us-central1-a","us-central1-b","us-central1-f"]network="vpc-01"subnetwork="us-central1-01"ip_range_pods="us-central1-01-gke-01-pods"ip_range_services="us-central1-01-gke-01-services"http_load_balancing=falsehorizontal_pod_autoscaling=truenetwork_policy=truenode_pools=[    {      name="default-node-pool"      machine_type="e2-medium"      node_locations="us-central1-b,us-central1-c"      min_count=1      max_count=100      local_ssd_count=0      disk_size_gb=100      disk_type="pd-standard"      image_type="COS"      auto_repair=true      auto_upgrade=true      service_account="project-service-account@<PROJECT ID>.iam.gserviceaccount.com"      preemptible=false      initial_node_count=80    },  ]node_pools_oauth_scopes={    all= []    default-node-pool= ["https://www.googleapis.com/auth/cloud-platform",    ]  }node_pools_labels={    all= {}    default-node-pool= {      default-node-pool=true    }  }node_pools_metadata={    all= {}    default-node-pool= {      node-pool-metadata-custom-value="my-node-pool"    }  }node_pools_taints={    all= []    default-node-pool= [      {        key="default-node-pool"        value=true        effect="PREFER_NO_SCHEDULE"      },    ]  }node_pools_tags={    all= []    default-node-pool= ["default-node-pool",    ]  }}

Then perform the following commands on the root folder:

  • terraform init to get the plugins
  • terraform plan to see the infrastructure plan
  • terraform apply to apply the infrastructure build
  • terraform destroy to destroy the built infrastructure

Inputs

NameDescriptionTypeDefaultRequired
add_cluster_firewall_rulesCreate additional firewall rulesboolfalseno
basic_auth_passwordThe password to be used with Basic Authentication.string""no
basic_auth_usernameThe username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration.string""no
cluster_autoscalingCluster autoscaling configuration. Seemore details
object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
{
"enabled": false,
"max_cpu_cores": 0,
"max_memory_gb": 0,
"min_cpu_cores": 0,
"min_memory_gb": 0
}
no
cluster_ipv4_cidrThe IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR.anynullno
cluster_resource_labelsThe GCE resource labels (a map of key/value pairs) to be applied to the clustermap(string){}no
configure_ip_masqEnables the installation of ip masquerading, which is usually no longer required when using aliasied IP addresses. IP masquerading uses a kubectl call, so when you have a private cluster, you will need access to the API server.boolfalseno
create_service_accountDefines if service account specified to run nodes should be created.booltrueno
database_encryptionApplication-layer Secrets Encryption settings. The object format is {state = string, key_name = string}. Valid values of state are: "ENCRYPTED"; "DECRYPTED". key_name is the name of a CloudKMS key.list(object({ state = string, key_name = string }))
[
{
"key_name": "",
"state": "DECRYPTED"
}
]
no
default_max_pods_per_nodeThe maximum number of pods to schedule per nodenumber110no
descriptionThe description of the clusterstring""no
disable_legacy_metadata_endpointsDisable the /0.1/ and /v1beta1/ metadata server endpoints on the node. Changing this value will cause all node pools to be recreated.booltrueno
enable_binary_authorizationEnable BinAuthZ Admission controllerboolfalseno
enable_network_egress_exportWhether to enable network egress metering for this cluster. If enabled, a daemonset will be created in the cluster to meter network egress traffic.boolfalseno
enable_resource_consumption_exportWhether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export.booltrueno
enable_shielded_nodesEnable Shielded Nodes features on all nodes in this clusterbooltrueno
enable_vertical_pod_autoscalingVertical Pod Autoscaling automatically adjusts the resources of pods controlled by itboolfalseno
firewall_inbound_portsList of TCP ports for admission/webhook controllerslist(string)
[
"8443",
"9443",
"15017"
]
no
firewall_priorityPriority rule for firewall rulesnumber1000no
gcloud_upgradeWhether to upgrade gcloud at runtimeboolfalseno
grant_registry_accessGrants created cluster-specific service account storage.objectViewer role.boolfalseno
horizontal_pod_autoscalingEnable horizontal pod autoscaling addonbooltrueno
http_load_balancingEnable httpload balancer addonbooltrueno
identity_namespaceWorkload Identity namespace. (Default value ofenabled automatically sets project based namespace[project_id].svc.id.goog)string"enabled"no
impersonate_service_accountAn optional service account to impersonate for gcloud commands. If this service account is not specified, the module will use Application Default Credentials.string""no
initial_node_countThe number of nodes to create in this cluster's default node pool.number0no
ip_masq_link_localWhether to masquerade traffic to the link-local prefix (169.254.0.0/16).boolfalseno
ip_masq_resync_intervalThe interval at which the agent attempts to sync its ConfigMap file from the disk.string"60s"no
ip_range_podsThename of the secondary subnet ip range to use for podsstringn/ayes
ip_range_servicesThename of the secondary subnet range to use for servicesstringn/ayes
issue_client_certificateIssues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive!boolfalseno
kubernetes_versionThe Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region.string"latest"no
logging_serviceThe logging service that the cluster should write logs to. Available options include logging.googleapis.com, logging.googleapis.com/kubernetes (beta), and nonestring"logging.googleapis.com/kubernetes"no
maintenance_start_timeTime window specified for daily or recurring maintenance operations in RFC3339 formatstring"05:00"no
master_authorized_networksList of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists).list(object({ cidr_block = string, display_name = string }))[]no
monitoring_serviceThe 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, monitoring.googleapis.com/kubernetes (beta) and nonestring"monitoring.googleapis.com/kubernetes"no
nameThe name of the cluster (required)stringn/ayes
networkThe VPC network to host the cluster in (required)stringn/ayes
network_policyEnable network policy addonbooltrueno
network_policy_providerThe network policy provider.string"CALICO"no
network_project_idThe project ID of the shared VPC's host (for shared vpc support)string""no
node_metadataSpecifies how node metadata is exposed to the workload running on the nodestring"GKE_METADATA_SERVER"no
node_poolsList of maps containing node poolslist(map(string))
[
{
"name": "default-node-pool"
}
]
no
node_pools_labelsMap of maps containing node labels by node-pool namemap(map(string))
{
"all": {},
"default-node-pool": {}
}
no
node_pools_metadataMap of maps containing node metadata by node-pool namemap(map(string))
{
"all": {},
"default-node-pool": {}
}
no
node_pools_oauth_scopesMap of lists containing node oauth scopes by node-pool namemap(list(string))
{
"all": [
"https://www.googleapis.com/auth/cloud-platform"
],
"default-node-pool": []
}
no
node_pools_tagsMap of lists containing node network tags by node-pool namemap(list(string))
{
"all": [],
"default-node-pool": []
}
no
node_pools_taintsMap of lists containing node taints by node-pool namemap(list(object({ key = string, value = string, effect = string })))
{
"all": [],
"default-node-pool": []
}
no
non_masquerade_cidrsList of strings in CIDR notation that specify the IP address ranges that do not use IP masquerading.list(string)
[
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16"
]
no
project_idThe project ID to host the cluster in (required)stringn/ayes
regionThe region to host the cluster in (optional if zonal cluster / required if regional)stringnullno
regionalWhether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)booltrueno
registry_project_idProject holding the Google Container Registry. If empty, we use the cluster project. If grant_registry_access is true, storage.objectViewer role is assigned on this project.string""no
release_channelThe release channel of this cluster. Accepted values areUNSPECIFIED,RAPID,REGULAR andSTABLE. Defaults toUNSPECIFIED.stringnullno
remove_default_node_poolRemove default node pool while setting up the clusterboolfalseno
resource_usage_export_dataset_idThe ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export.string""no
service_accountThe service account to run nodes as if not overridden innode_pools. The create_service_account variable default value (true) will cause a cluster-specific service account to be created.string""no
skip_provisionersFlag to skip all local-exec provisioners. It breaksstub_domains andupstream_nameservers variables functionality.boolfalseno
stub_domainsMap of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS servermap(list(string)){}no
subnetworkThe subnetwork to host the cluster in (required)stringn/ayes
upstream_nameserversIf specified, the values replace the nameservers taken by default from the node’s /etc/resolv.conflist(string)[]no
zonesThe zones to host the cluster in (optional if regional cluster / required if zonal)list(string)[]no

Outputs

NameDescription
ca_certificateCluster ca certificate (base64 encoded)
endpointCluster endpoint
horizontal_pod_autoscaling_enabledWhether horizontal pod autoscaling enabled
http_load_balancing_enabledWhether http load balancing enabled
identity_namespaceWorkload Identity namespace
instance_group_urlsList of GKE generated instance groups
locationCluster location (region if regional cluster, zone if zonal cluster)
logging_serviceLogging service used
master_authorized_networks_configNetworks from which access to master is permitted
master_versionCurrent master kubernetes version
min_master_versionMinimum master kubernetes version
monitoring_serviceMonitoring service used
nameCluster name
network_policy_enabledWhether network policy enabled
node_pools_namesList of node pools names
node_pools_versionsList of node pools versions
regionCluster region
release_channelThe release channel of this cluster
service_accountThe service account to default running nodes as if not overridden innode_pools.
typeCluster type (regional / zonal)
zonesList of zones in which the cluster resides

node_pools variable

The node_pools variable takes the following parameters:

NameDescriptionDefaultRequirement
accelerator_countThe number of the guest accelerator cards exposed to this instance0Optional
accelerator_typeThe accelerator type resource to expose to the instance" "Optional
auto_repairWhether the nodes will be automatically repairedtrueOptional
autoscalingConfiguration required by cluster autoscaler to adjust the size of the node pool to the current cluster usagetrueOptional
auto_upgradeWhether the nodes will be automatically upgradedtrue (if cluster is regional)Optional
disk_size_gbSize of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB100Optional
disk_typeType of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd')pd-standardOptional
effectEffect for the taintRequired
enable_integrity_monitoringEnables monitoring and attestation of the boot integrity of the instance. The attestation is performed against the integrity policy baseline. This baseline is initially derived from the implicitly trusted boot image when the instance is created.trueOptional
enable_secure_bootSecure Boot helps ensure that the system only runs authentic software by verifying the digital signature of all boot components, and halting the boot process if signature verification fails.falseOptional
image_typeThe image type to use for this node. Note that changing the image type will delete and recreate all nodes in the node poolCOSOptional
initial_node_countThe initial number of nodes for the pool. In regional or multi-zonal clusters, this is the number of nodes per zone. Changing this will force recreation of the resource. Defaults to the value of min_count" "Optional
keyThe key required for the taintRequired
local_ssd_countThe amount of local SSD disks that will be attached to each cluster node0Optional
machine_typeThe name of a Google Compute Engine machine typee2-mediumOptional
max_countMaximum number of nodes in the NodePool. Must be >= min_count100Optional
min_countMinimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true1Optional
nameThe name of the node poolRequired
node_countThe number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusersRequired
node_locationsThe list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified" "Optional
node_metadataOptions to expose the node metadata to the workload running on the nodeOptional
preemptibleA boolean that represents whether or not the underlying node VMs are preemptiblefalseOptional
service_accountThe service account to be used by the Node VMs" "Optional
tagsThe list of instance tags applied to all nodesRequired
valueThe value for the taintRequired
versionThe Kubernetes version for the nodes in this pool. Should only be set if auto_upgrade is false" "Optional

Requirements

Before this module can be used on a project, you must ensure that the following pre-requisites are fulfilled:

  1. Terraform and kubectl areinstalled on the machine where Terraform is executed.
  2. The Service Account you execute the module with has the rightpermissions.
  3. The Compute Engine and Kubernetes Engine APIs areactive on the project you will launch the cluster in.
  4. If you are using a Shared VPC, the APIs must also be activated on the Shared VPC host project and your service account needs the proper permissions there.

Theproject factory can be used to provision projects with the correct APIs active and the necessary Shared VPC connections.

Software Dependencies

Kubectl

Terraform and Plugins

gcloud

Some submodules use theterraform-google-gcloud module. By default, this module assumes you already have gcloud installed in your $PATH.See themodule documentation for more information.

Configure a Service Account

In order to execute this module you must have a Service Account with thefollowing project roles:

  • roles/compute.viewer
  • roles/compute.securityAdmin (only required ifadd_cluster_firewall_rules is set totrue)
  • roles/container.clusterAdmin
  • roles/container.developer
  • roles/iam.serviceAccountAdmin
  • roles/iam.serviceAccountUser
  • roles/resourcemanager.projectIamAdmin (only required ifservice_account is set tocreate)

Additionally, ifservice_account is set tocreate andgrant_registry_access is requested, the service account requires the following role on theregistry_project_id project:

  • roles/resourcemanager.projectIamAdmin

Enable APIs

In order to operate with the Service Account you must activate the following APIs on the project where the Service Account was created:

  • Compute Engine API - compute.googleapis.com
  • Kubernetes Engine API - container.googleapis.com

About

A Terraform module for configuring GKE clusters.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL75.2%
  • Ruby14.3%
  • Shell6.8%
  • Python3.0%
  • Other0.7%

[8]ページ先頭

©2009-2025 Movatter.jp