Hen*_*nke 2 vpn networking google-cloud-platform kubernetes google-kubernetes-engine
我有一个 VPC 网络,其子网范围为 10.100.0.0/16,节点驻留在其中。有一个路由和防火墙规则应用于范围 10.180.102.0/23,它路由并允许进出 VPN 隧道的流量。
如果我在 10.100.0.0/16 范围内部署节点,则可以 ping 10.180.102.0/23 范围内的设备。但是,在该节点内运行的 pod 无法 ping 10.180.102.0/23 范围内的设备。我认为这与 pod 位于不同的 IP 范围(10.12.0.0/14)有关。
如何配置我的网络,以便我可以与 10.180.102.0/23 范围内的设备进行 ping/通信?
我不太记得究竟如何解决,但我正在发布我必须帮助@tdensmore 的内容。
您必须编辑 ip-masq-agent(这是一个在 GKE 上运行的代理,用于伪装 IP),此配置负责让节点内的 pod 到达 GCP VPC 网络的其他部分,更具体地说是 VPN。因此,它允许 Pod 与可通过 VPN 访问的设备进行通信。
首先,我们将在kube-system命名空间内工作,我们将把配置我们的 ip-masq-agent 的 configmap 放在一个config文件中:
nonMasqueradeCIDRs:
- 10.12.0.0/14 # The IPv4 CIDR the cluster is using for Pods (required)
- 10.100.0.0/16 # The IPv4 CIDR of the subnetwork the cluster is using for Nodes (optional, works without but I guess its better with it)
masqLinkLocal: false
resyncInterval: 60s
Run Code Online (Sandbox Code Playgroud)
并运行 kubectl create configmap ip-masq-agent --from-file config --namespace kube-system
之后,配置 ip-masq-agent,把它放在一个ip-masq-agent.yml文件中:
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: ip-masq-agent
namespace: kube-system
spec:
template:
metadata:
labels:
k8s-app: ip-masq-agent
spec:
hostNetwork: true
containers:
- name: ip-masq-agent
image: gcr.io/google-containers/ip-masq-agent-amd64:v2.4.1
args:
- --masq-chain=IP-MASQ
# To non-masquerade reserved IP ranges by default, uncomment the line below.
# - --nomasq-all-reserved-ranges
securityContext:
privileged: true
volumeMounts:
- name: config
mountPath: /etc/config
volumes:
- name: config
configMap:
# Note this ConfigMap must be created in the same namespace as the daemon pods - this spec uses kube-system
name: ip-masq-agent
optional: true
items:
# The daemon looks for its config in a YAML file at /etc/config/ip-masq-agent
- key: config
path: ip-masq-agent
tolerations:
- effect: NoSchedule
operator: Exists
- effect: NoExecute
operator: Exists
- key: "CriticalAddonsOnly"
operator: "Exists"
Run Code Online (Sandbox Code Playgroud)
并运行 kubectl -n kube-system apply -f ip-masq-agent.yml
注意:自从我这样做以来已经很长时间了,此链接中有更多信息:https : //cloud.google.com/kubernetes-engine/docs/how-to/ip-masquerade-agent