简体   繁体   English

从另一个Pod Kubernetes访问Pod

[英]Access pod from another pod kubernetes

I have 2 pods created. 我创建了2个豆荚。 one is grafana and another is influx pod. 一个是格拉法纳,另一个是潮豆荚。 I need to configure influx in grafana. 我需要在grafana中配置Influx。 I did see the below example. 我确实看到了以下示例。 I got bit confused by the way its configured. 我对其配置方式感到困惑。 Below is deployment and service file. 以下是部署和服务文件。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: influxdb
  labels:
    app: influxdb
spec:
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      containers:
      - name: influxdb
        image: influxdb
        ports:
        - containerPort: 8083
          name: admin
        - containerPort: 8086
          name: http
        resources:
          limits:
            memory: 2048Mi
            cpu: 100m  
        volumeMounts:
        - name: influxdb-data
          mountPath: /var/lib/influxdb
      volumes:
      - name: influxdb-data
        persistentVolumeClaim:
          claimName: influxdb-pvc-vol

Service file 服务档案

apiVersion: v1
kind: Service
metadata:
  name: influxdb
  labels:
    app: influxdb
spec:
  ports:
    - port: 3306
  selector:
    app: influxdb
  clusterIP: None

What does clusterIP: None do? clusterIP: None什么不做? he has exposed 3306 port and mapped it to node port 3306. So i believe i can access from other pod using 3306 port and its IP. 他已经公开了3306端口并将其映射到节点端口3306。所以我相信我可以使用3306端口及其IP从其他Pod进行访问。 But here i see i am able to access via http://influxdb:8086 How am i able to access via http://influxdb:8086 ? 但在这里,我看到我能够通过访问http://influxdb:8086我如何能够通过访问HTTP:// influxdb:8086

I can explain what's happening and why this works, but I still think this configuration doesn't make sense. 我可以解释发生了什么,为什么会起作用,但是我仍然认为这种配置没有意义。

The Deployment creates a Pod that runs InfluxDB which listens by default on port 8086. The containerPort here is purely informational, see the following from the Pod spec reference : 部署创建一个运行InfluxDB的Pod,该Pod默认在端口8086上进行侦听。此处的containerPort纯粹是信息性的,请参阅Pod规范参考中的以下内容:

primarily informational. 主要是信息性的。 Not specifying a port here DOES NOT prevent that port from being exposed. 在此处未指定端口并不能防止该端口暴露。 Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network. 任何从容器中的默认“ 0.0.0.0”地址监听的端口都可以从网络访问。

Now to the Service, which is created with a port 3306, which is odd but in this case doesn't matter because this is a Headless Service . 现在进入使用端口3306创建的服务,这很奇怪,但在这种情况下并不重要,因为这是无头服务 A headless service is a means to tell Kubernetes you don't want it's fancy networking features (like kube-proxy load balancing), instead you just want it to create DNS records for you. 无头服务是一种告诉Kubernetes您不希望它具有精美的网络功能(例如kube-proxy负载平衡)的方法,而只是希望它为您创建DNS记录。 By specifying ClusterIP: None you essentially make this a headless service. 通过指定ClusterIP: None您实际上可以使它成为无头服务。 Given that this service is not actually serving any traffic, the "Port" field here is meaningless. 考虑到该服务实际上并没有为任何流量提供服务,因此此处的“端口”字段毫无意义。

Now let's review what happens when you access http://influxdb:8086 : 现在,让我们回顾一下访问http:// influxdb:8086时发生的情况:

  1. your http client resolves the host influxdb to the Pod IP. 您的http客户端将主机influxdb解析为Pod IP。 This is possible thanks to the headless service. 多亏了无头服务,这才有可能。 Note again that the host resolves to the Pod IP, not a Service IP. 再次注意,主机解析为Pod IP,而不是服务IP。
  2. Since the Pod is serving on 8086, and since you reached it directly in it's private IP, it accepts your request and you have your reply. 由于Pod服务于8086,并且您是直接通过其专用IP到达的,因此该Pod接受您的请求并得到答复。

A service that defines the ClusterIP:none is known as a headless service 定义ClusterIP的服务:无被称为无头服务

For headless services that define selectors, the endpoints controller creates Endpoints records in the API, and modifies the DNS configuration to return A records (addresses) that point directly to the Pods backing the Service 对于定义选择器的无头服务,端点控制器在API中创建端点记录,并修改DNS配置以返回直接指向支持该服务的Pod的A记录(地址)。

Since there is only one influxdb pod, there is no need to load balance it and so no need for a service proxy, requests are routed directly to the pod. 由于只有一个Influxdb Pod,因此无需对其进行负载平衡,因此也不需要服务代理,因此请求将直接路由到Pod。

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

相关问题 使用 kubernetes url 从另一个 pod 访问 pod - Access pod from another pod with kubernetes url Kubernetes从另一个Pod找到Pod IP - Kubernetes to find Pod IP from another Pod 从另一个 pod 重新启动 kubernetes pod - Restarting a kubernetes pod from another pod 从Pod进行Kubernetes API访问 - Kubernetes API Access from Pod Kubernetes-如何在 kubernetes 中将数据从一个 Pod 发送到另一个 Pod - Kubernetes-How to send data from a pod to another pod in kubernetes 如何(正确)在 Kubernetes 上部署 MongoDB 并从另一个 Pod/Job 访问它? - How to (properly) Deploy MongoDB on Kubernetes and Access it from Another Pod/Job? 如何通过 Kubernetes 中的另一个 pod 访问部署在一个 pod 上的服务? - How to access the service deployed on one pod via another pod in Kubernetes? 谷歌发布订阅。 从 AppEngine 到 Kubernetes pod 以及从一个 Kubernetes pod 到另一个 Kubernetes pod 的通信 - Google PubSub. Communication From AppEngine to Kubernetes pod and from one Kubernetes pod to another Kubernetes pod 从Pod内部访问Kubernetes Pod的日志文件? - Access Kubernetes pod's log files from inside the pod? 从 Kubernetes 中的不同 pod 访问 pod 中生成的数据 - Access data produced in a pod from a different pod in Kubernetes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM