Difference between revisions of "Gke.tf"
Jump to navigation
Jump to search
(19 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{lc}} | ||
+ | * https://github.com/hashicorp/learn-terraform-provision-gke-cluster/blob/main/gke.tf | ||
+ | [[location]] = [[var.region]] or location = [[us-central1-a]] | ||
+ | |||
+ | == Code == | ||
* https://github.com/hashicorp/learn-terraform-provision-gke-cluster/blob/main/gke.tf | * https://github.com/hashicorp/learn-terraform-provision-gke-cluster/blob/main/gke.tf | ||
+ | variable "gke_username" { | ||
+ | default = "" | ||
+ | description = "gke username" | ||
+ | } | ||
+ | |||
+ | variable "gke_password" { | ||
+ | default = "" | ||
+ | description = "gke password" | ||
+ | } | ||
+ | |||
+ | variable "gke_num_nodes" { | ||
+ | default = 2 | ||
+ | description = "number of gke nodes" | ||
+ | } | ||
+ | |||
+ | # GKE cluster | ||
+ | resource "[[google_container_cluster]]" "primary" { | ||
+ | name = "${var.project_id}-gke" | ||
+ | location = var.region | ||
+ | |||
+ | # We can't create a cluster with no node pool defined, but we want to only use | ||
+ | # separately managed node pools. So we create the smallest possible default | ||
+ | # node pool and immediately delete it. | ||
+ | remove_default_node_pool = true | ||
+ | initial_node_count = 1 | ||
+ | |||
+ | network = google_compute_network.vpc.name | ||
+ | subnetwork = google_compute_subnetwork.subnet.name | ||
+ | } | ||
+ | |||
+ | # Separately Managed Node Pool | ||
+ | resource "[[google_container_node_pool]]" "primary_nodes" { | ||
+ | name = "${google_container_cluster.primary.name}" | ||
+ | location = var.region | ||
+ | cluster = google_container_cluster.primary.name | ||
+ | node_count = var.gke_num_nodes | ||
+ | |||
+ | [[node_config]] { | ||
+ | oauth_scopes = [ | ||
+ | "https://www.googleapis.com/auth/logging.write", | ||
+ | "https://www.googleapis.com/auth/monitoring", | ||
+ | ] | ||
+ | |||
+ | labels = { | ||
+ | env = var.project_id | ||
+ | } | ||
+ | |||
+ | # preemptible = true | ||
+ | [[machine_type]] = "[[n1-standard-1]]" | ||
+ | tags = ["gke-node", "${var.project_id}-gke"] | ||
+ | metadata = { | ||
+ | disable-legacy-endpoints = "true" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | <pre> | ||
+ | # # Kubernetes provider | ||
+ | # # The Terraform Kubernetes Provider configuration below is used as a learning reference only. | ||
+ | # # It references the variables and resources provisioned in this file. | ||
+ | # # We recommend you put this in another file -- so you can have a more modular configuration. | ||
+ | # # https://learn.hashicorp.com/terraform/kubernetes/provision-gke-cluster#optional-configure-terraform-kubernetes-provider | ||
+ | # # To learn how to schedule deployments and services using the provider, go here: https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider. | ||
+ | |||
+ | # provider "kubernetes" { | ||
+ | # load_config_file = "false" | ||
+ | |||
+ | # host = google_container_cluster.primary.endpoint | ||
+ | # username = var.gke_username | ||
+ | # password = var.gke_password | ||
+ | |||
+ | # client_certificate = google_container_cluster.primary.master_auth.0.client_certificate | ||
+ | # client_key = google_container_cluster.primary.master_auth.0.client_key | ||
+ | # cluster_ca_certificate = google_container_cluster.primary.master_auth.0.cluster_ca_certificate | ||
+ | # } | ||
+ | </pre> | ||
+ | |||
+ | == Related == | ||
+ | * <code>[[machine_type]]</code>: <code>[[n1-standard-1]], [[g1-small]]</code> | ||
+ | * <code>[[google_compute_instance]]</code> | ||
+ | * <code>[[eks-cluster.tf]]</code> | ||
+ | * <code>[[gcloud container clusters describe your-cluster-name --region us-central1-a]]</code> | ||
+ | == See also == | ||
+ | * {{gke.tf}} | ||
+ | * {{tf GKE}} | ||
− | [[ | + | [[Category:GKE]] |
Latest revision as of 17:12, 7 December 2023
location = var.region or location = us-central1-a
Code[edit]
variable "gke_username" { default = "" description = "gke username" } variable "gke_password" { default = "" description = "gke password" } variable "gke_num_nodes" { default = 2 description = "number of gke nodes" } # GKE cluster resource "google_container_cluster" "primary" { name = "${var.project_id}-gke" location = var.region # We can't create a cluster with no node pool defined, but we want to only use # separately managed node pools. So we create the smallest possible default # node pool and immediately delete it. remove_default_node_pool = true initial_node_count = 1 network = google_compute_network.vpc.name subnetwork = google_compute_subnetwork.subnet.name } # Separately Managed Node Pool resource "google_container_node_pool" "primary_nodes" { name = "${google_container_cluster.primary.name}" location = var.region cluster = google_container_cluster.primary.name node_count = var.gke_num_nodes node_config { oauth_scopes = [ "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring", ]
labels = { env = var.project_id }
# preemptible = true machine_type = "n1-standard-1" tags = ["gke-node", "${var.project_id}-gke"] metadata = { disable-legacy-endpoints = "true" } } }
# # Kubernetes provider # # The Terraform Kubernetes Provider configuration below is used as a learning reference only. # # It references the variables and resources provisioned in this file. # # We recommend you put this in another file -- so you can have a more modular configuration. # # https://learn.hashicorp.com/terraform/kubernetes/provision-gke-cluster#optional-configure-terraform-kubernetes-provider # # To learn how to schedule deployments and services using the provider, go here: https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider. # provider "kubernetes" { # load_config_file = "false" # host = google_container_cluster.primary.endpoint # username = var.gke_username # password = var.gke_password # client_certificate = google_container_cluster.primary.master_auth.0.client_certificate # client_key = google_container_cluster.primary.master_auth.0.client_key # cluster_ca_certificate = google_container_cluster.primary.master_auth.0.cluster_ca_certificate # }
Related[edit]
machine_type
:n1-standard-1, g1-small
google_compute_instance
eks-cluster.tf
gcloud container clusters describe your-cluster-name --region us-central1-a
See also[edit]
Advertising: