如何将现有的GKE集群更改为GKE私有集群?我是否能够根据防火墙规则从互联网连接到 Kubectl API,还是应该拥有堡垒主机?我不想实施Cloud Nat
or nat gateway
。我有一个鱿鱼代理虚拟机,可以处理 Pod 的互联网访问。我只需要能够连接到 Kubectl 来应用或修改任何内容。
我不确定如何修改我编写的现有模块以使节点成为私有节点,并且我不确定如果我尝试应用与私有 gke 集群相关的新更改,集群是否会被删除。
resource "google_container_cluster" "primary" {
name = "prod"
network = "prod"
subnetwork = "private-subnet-a"
location = "us-west1-a"
remove_default_node_pool = true
initial_node_count = 1
depends_on = [var.depends_on_vpc]
}
resource "google_container_node_pool" "primary_nodes" {
depends_on = [var.depends_on_vpc]
name = "prod-node-pool"
location = "us-west1-a"
cluster = google_container_cluster.primary.name
node_count = 2
node_config {
preemptible = false
machine_type = "n1-standard-2"
metadata = {
disable-legacy-endpoints = "true"
}
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/compute",
]
}
}
回答问题的部分:
如何将现有的GKE集群更改为GKE私有集群?
GKE
环境:Private cluster
是不可变的。该设置只能在GKE
集群配置。
要将集群创建为私有集群,您可以:
- 创建一个新的
GKE
私有集群。
- Duplicate existing cluster and set it to private:
- 此设置可用于
GCP Cloud Console
-> Kubernetes Engine
-> CLUSTER-NAME
-> Duplicate
- 此设置将克隆之前集群的基础架构配置,但不会克隆工作负载(
Pods
, Deployments
, etc.)
我是否能够根据防火墙规则从互联网连接到 Kubectl API,还是应该拥有堡垒主机?
是的,您可以,但这在很大程度上取决于您在测试过程中选择的配置GKE
集群创建过程。
至于连接到您的能力GKE
私有集群,有一个专门的文档:
- Cloud.google.com:Kubernetes Engine:文档:如何:私有集群 https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters
至于如何使用 Terraform 创建私有集群,有一个专门的站点,其中包含特定于GKE
。还有一些参数负责配置private
簇:
- Registry.terraform.io:提供商:Hashicorp:Google:最新:文档:资源:容器集群 https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
至于创建私有的基本示例GKE
与 Terraform 集群:
provider "google" {
project = "INSERT_PROJECT_HERE"
region = "europe-west3"
zone = "europe-west3-c"
}
resource "google_container_cluster" "primary-cluster" {
name = "gke-private"
location = "europe-west3-c"
initial_node_count = 1
private_cluster_config {
enable_private_nodes = "true"
enable_private_endpoint = "false" # this option will make your cluster available through public endpoint
master_ipv4_cidr_block = "172.16.0.0/28"
}
ip_allocation_policy {
cluster_secondary_range_name = ""
services_secondary_range_name = ""
}
node_config {
machine_type = "e2-medium"
}
}
附注!
我创建了一个公共GKE
集群,修改了.tf
负责创建它以支持私有集群。运行后:$ terraform plan
Terraform 回复了将重新创建集群的信息.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)