从 GCP 上的实例访问 Kubernetes Pods

Access to Kubernetes Pods from instance on GCP

鉴于:

问题: 为什么无法从 VPN 实例 ping / curl / 访问 POD ip?

我需要完成的是通过 VPN 隧道从本地网络内部连接到 POD ip。

我做错了什么?

编辑: 这同样适用于 NodePorts:

@vpn-gateway:~$ curl -vvv 10.7.244.149:666
* Rebuilt URL to: 10.7.244.149:666/
*   Trying 10.7.244.149...
* TCP_NODELAY set

VPN网关无法访问NodePort

EDIT2: 服务配置:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: scs-ui
  name: scs-ui
spec:
  clusterIP: None
  ports:
  - name: application
    port: 666
  selector:
    app: scs-ui

如果您没有使用 Nodeport、Load balancer 和 clusterIp 等任何一种服务将您的 pod 暴露在互联网上,那么您的 pod 无论如何都无法在 kubernetes 集群之外访问。

问题:为什么从VPN实例无法ping / curl /访问POD ip?

Answer : without exposing pod outside the world you can not ping pod you can do it in kubernetes cluster network or inside cluster only your pod can be resolved, ping possible

要从本地网络访问您的 pod,只需使用负载均衡器公开 pod 的端口即可。 Nodeport 和 loadbalancer 与 k8s 服务一起工作。

使用 service expose pod,您可以 ping 并执行所有操作。

刚刚找到解决方案:

在VPN/Kubernetes的地址范围内创建一个LB。通过这种方式,请求通过 VPN 路由到我本地机器的服务中。

apiVersion: v1
kind: Service
metadata:
  name: elassandra-ingress
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  labels:
    app: elassandra-ingress
spec:
  type: LoadBalancer
  loadBalancerIP: 10.164.0.100
  ports:
  - port: 9042
    protocol: TCP
  selector:
    app: elassandra