Lia*_*eys 8 networking google-cloud-platform kubernetes google-kubernetes-engine terraform
我使用以下命令在 Google Kubernetes Engine (GKE) 上对私有 Kubernetes 集群进行了地形改造(Terraform 版本 11.10).tf:
module "nat" {
source = "GoogleCloudPlatform/nat-gateway/google"
region = "europe-west1"
network = "default"
subnetwork = "default"
}
resource "google_container_node_pool" "cluster_1_np" {
name = "cluster-1-np"
region = "europe-west1"
cluster = "${google_container_cluster.cluster_1.name}"
initial_node_count = 1
lifecycle {
ignore_changes = ["node_count"]
}
autoscaling {
min_node_count = 1
max_node_count = 50
}
management {
auto_repair = true
auto_upgrade = true
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/pubsub",
]
tags = ["${module.nat.routing_tag_regional}"]
}
}
resource "google_container_cluster" "cluster_1" {
provider = "google-beta"
name = "cluster-1"
region = "europe-west1"
remove_default_node_pool = true
private_cluster_config {
enable_private_endpoint = false
enable_private_nodes = true
master_ipv4_cidr_block = "172.16.0.0/28"
}
ip_allocation_policy {
create_subnetwork = true
}
lifecycle {
ignore_changes = ["initial_node_count", "network_policy", "node_config", "node_pool"]
}
node_pool {
name = "default-pool"
}
addons_config {
http_load_balancing {
disabled = false
}
horizontal_pod_autoscaling {
disabled = false
}
}
master_authorized_networks_config {
cidr_blocks = [
{
cidr_block = "<MY_OFFICE_CIDR>"
display_name = "Office"
},
]
}
}
Run Code Online (Sandbox Code Playgroud)
效果很好,给了我一个私有集群(NAT 工作,让节点可以访问互联网),我办公室里的机器可以运行kubectl命令与它交互,没有麻烦。
我现在面临的问题是集成任何基于 Web 的持续集成 (CI) 或持续部署 (CD)。私有集群是谷歌云平台(GCP)的一个新特性,这方面的文档有点欠缺。
到目前为止,我的尝试完全失败,我的网络知识根本不够。我尝试了这个解决方案,但似乎自动化机器必须与代理在同一网络上。
我发现了这个类似的 SO 问题(几乎完全相同,但他是特定于 Cloud Build 的)。在对该问题的一个答案的评论中,OP 提到他找到了一种解决方法,他可以临时修改构建机器的主授权网络,但他没有确切说明他是如何执行此操作的。
我试图复制他的解决方法,但相关gcloud命令似乎能够添加到update网络列表,或者完全删除所有网络,而不是像他的评论所暗示的那样一次添加/删除一个。
非常感谢网络向导的帮助。
这是与公共云中的CI 系统(如CircleCI或Travis)交互时的常见问题。您可以使用此命令来更新您的master authorized networks
gcloud container clusters update [CLUSTER_NAME] \
--enable-master-authorized-networks \
--master-authorized-networks=<MY_OFFICE_CIDR>,<NEW-CIDR-FROM-CI> \
--zone=<your-zone>
Run Code Online (Sandbox Code Playgroud)
要删除 CI 系统网络,您可以执行以下操作(只需从 cli 中删除网络):
gcloud container clusters update [CLUSTER_NAME] \
--enable-master-authorized-networks \
--master-authorized-networks=<MY_OFFICE_CIDR> \
--zone=<your-zone>
Run Code Online (Sandbox Code Playgroud)
要完全删除所有授权网络(禁用):
gcloud container clusters update [CLUSTER_NAME] \
--no-enable-master-authorized-networks
Run Code Online (Sandbox Code Playgroud)
您也可以从 UI 执行此操作:
它实际上记录在这里。
| 归档时间: |
|
| 查看次数: |
2474 次 |
| 最近记录: |