出于培训目的,我尝试在不使用GKE的情况下在GCP上设置自己的集群。
我已经成功地使用kubeadm创建了一个包含2个节点的集群。我正在运行一个nginx应用程序,并用NodePort公开了它。我所有的pod和服务都在运行。
kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master-1 Ready control-plane,master 4m43s v1.20.0 10.132.0.2 <none> Debian GNU/Linux 9 (stretch) 4.9.0-14-amd64 docker://19.3.14
worker-1 Ready <none> 3m9s v1.20.0 10.132.0.3 <none> Debian GNU/Linux 9 (stretch) 4.9.0-14-amd64 docker://19.3.14kubectl get svc -owide
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 37m <none>
nginx NodePort 10.102.241.17 <none> 80:30695/TCP 31m app=nginx这是我的google_compute_instance地形
resource "google_compute_instance" "default" {
name = var.vm_name
machine_type = "e2-standard-2"
zone = "europe-west1-b"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = var.network
access_config {
// Include this section to give the VM an external IP address
}
}
metadata_startup_script = file("./scripts/bootstrap.sh")
tags = ["node"]
}这是我的terrafom防火墙:
resource "google_compute_network" "vpc_network" {
name = "k8s-node"
}
resource "google_compute_firewall" "default" {
name = "k8s-firewall"
network = google_compute_network.vpc_network.name
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["80", "6443", "30000-32767"]
}
source_tags = ["node"]
source_ranges = ["0.0.0.0/0"]
}使用此配置,我无法使用http://my-instance-ip:30695访问我的实例...我暂停了。
但是当我允许我的GCP控制台中的所有协议和端口用于我的防火墙规则k8s-firewall时,它是有效的。允许所有协议和端口后,我可以使用http://my-instance-ip:30695正确访问我的应用程序...
我的防火墙有什么问题?对我来说,当我只允许30000到32767之间的范围时,它应该可以工作,因为k8s将这个范围用于NodePort服务。
发布于 2020-12-16 00:42:37
看起来问题出在下面这行:
source_tags = ["node"]只要看一下Source标签的定义:
仅允许来自具有这些标记的来源的
流量。要输入多个标记名称,请在每个标记名称后按Return键。
当从任何IP访问您的计算引擎虚拟机时,您没有在此类源IP上应用"node"标签,因此您的流量仍会被过滤掉。您当前的规则基本上是:允许来自所有IP地址的传入流量,但也要验证它是否来自应用了"node"标签的来源。如果没有,则拒绝该流量。
发布于 2020-12-19 14:56:28
source-tags不控制外部IP地址上的流量。因此,对于不是来自另一个实例的流量,默认规则是拒绝。
source_tags控制的唯一流量是来自其他实例的流量。
防火墙规则的目标是控制流向已标记实例的流量。
解决方案:
将source_tags更改为target_tags。
https://stackoverflow.com/questions/65297738
复制相似问题