[英]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时发生的情况:
influxdb
to the Pod IP. influxdb
解析为Pod IP。 This is possible thanks to the headless service. 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.