简体   繁体   English

从GCP上的实例访问Kubernetes Pod

[英]Access to Kubernetes Pods from instance on GCP

Given: 鉴于:

  • VPN instance. VPN实例。 This instance runs on internal IP 10.6.240.3 该实例在内部IP 10.6.240.3上运行
  • Kubernetes POD running on internal IP 10.6.240.4 在内部IP 10.6.240.4上运行的Kubernetes POD

Question: Why is it not possible to ping / curl / access the POD ip from the VPN instance? 问题:为什么无法从VPN实例ping /卷曲/访问POD ip?

What I need to archieve is to connect to the POD ip from inside my local network through the VPN tunnel. 我需要存档的是通过VPN隧道从本地网络内部连接到POD ip。

What am I doing wrong? 我究竟做错了什么?

EDIT: Same applies to NodePorts: 编辑:同样适用于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

The VPN gateway cannot access the NodePort VPN网关无法访问NodePort

EDIT2: Service configuration: 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

Just found an solution: 刚刚找到解决方案:

Create a LB in the address range of the VPN / Kubernetes. 在VPN / Kubernetes的地址范围内创建一个LB。 This way the request is routed through the VPN into the service from my local mashine. 这样,请求就可以通过VPN从我的本地mashine路由到服务中。

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

if you have not exposed your pod to the internet using any one of service like Nodeport, Load balancer and clusterIp they your pod cannot be accessible outside the kubernetes cluster any how. 如果您尚未使用Nodeport,Load Balancer和clusterIp之类的任何一项服务将Pod暴露于Internet,则无论如何都无法在Kubernetes集群外部访问您的Pod。

Question: Why is it not possible to ping / curl / access the POD ip from the VPN instance? 问题:为什么无法从VPN实例ping /卷曲/访问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

To acces your pod from local network simply expose port of pod on expose it using load balancer. 要从本地网络访问Pod,只需使用负载均衡器在暴露Pod的端口时就暴露它。 Nodeport and loadbalancer work with k8s service. Nodeport和loadbalancer与k8s服务一起使用。

using service expose pod and you can ping and do everything. 使用服务公开pod,您可以ping并执行所有操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM