简体   繁体   English

Kubernetes服务Pod优先级

[英]Kubernetes service pod prioritization

I have the following scenario at hand and i would like to get the lowest possible latency between pods ( i do not wish to deploy all containers to same pod). 我手头有以下情况,我想使Pod之间的延迟最小(我不希望将所有容器都部署到同一Pod)。 So the following scenario is what i would like to achieve: 因此,以下情况是我想要实现的目标:

Lets say you have a Kubernetes cluster with 4 nodes: - on each node you have a sqlproxy to central database that is not part of kubernetes - on each node you have 4 pods that call database through that sqlproxy 假设您有一个带有4个节点的Kubernetes集群:-在每个节点上都有一个sqlproxy到不属于kubernetes的中央数据库-在每个节点上都有4个Pod通过该sqlproxy调用数据库

As far as I have learned when I create a service that, service distributes traffic "randomly" between pods in service. 据我在创建服务时所了解的,服务在服务中的各个Pod之间“随机”分配流量。 Meaning that pod from node 1 could call sqlproxy on node 4 and pod on node 2 could call sqlproxy on node 3 and so on. 这意味着节点1的pod可以在节点4上调用sqlproxy,节点2的pod可以在节点3上调用sqlproxy,依此类推。

I would like to achieve that pods on node 1 call whenever possible sqlproxy on node 1, so it has the minimum latency. 我想在节点1上尽可能使用sqlproxy来实现对节点1上的pod的调用,因此它具有最小的延迟。

Is this even possible or are the delays between nodes so small they can be disregarded? 这是否可能,或者节点之间的延迟如此之小以至于可以忽略不计?

Deploy the SQL proxy as a side car to your app (two containers in one pod, one being the app, one being the proxy) . 将SQL代理作为辅助工具部署到您的应用程序(一个容器中有两个容器,一个是应用程序,一个是代理程序)。

Your deployment will look something like this: 您的部署将如下所示:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: ...
  name: my-app
  labels:
    app: my-app

spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: << app image >>
          ports:
            - containerPort: 8080
        - name: sql-proxy
          image: << SQL proxy image >>
          ports:
            - containerPort: 3306

Now make the app connect to localhost:3306 to connect to the SQL proxy running in the same pod. 现在,使该应用程序连接到localhost:3306以连接到在同一容器中运行的SQL代理。 In that way you avoid the potentially expensive cross-node hop and keep the connection local. 这样,您可以避免潜在的昂贵的跨节点跃点,并将连接保持在本地。

The solution presented by @Oliver - running sqlproxy as a sidecar container in the same pod as the application - will probably give you the lowest latency. @Oliver提出的解决方案-将sqlproxy作为sidecar容器与应用程序放置在同一容器中-可能会给您带来最低的延迟。

If for some reason you still want to go with running one sqlproxy instance per node (eg to take advantage of database connection pooling and reuse), the application would need to dynamically discover at run-time the IP address of the node on which it is running, and use it to connect to the sqlproxy instance on that same node. 如果由于某种原因您仍然想在每个节点上运行一个sqlproxy实例(例如,利用数据库连接池和重用),则应用程序将需要在运行时动态发现其所在节点的IP地址。运行,并使用它连接到同一节点上的sqlproxy实例。

Below is a way to dynamically discover the IP address of the host node and set it as an environment variable (see also The Downward API in the Kubernetes docs): 以下是一种动态发现主机节点IP地址并将其设置为环境变量的方法(另请参见Kubernetes文档中的Downward API ):

...
spec:
  containers:
  - name: app-container-name
    image: <app-image>
    env:
    - name: POD_HOST_IP
      valueFrom:
        fieldRef:
          apiVersion: v1
          fieldPath: status.hostIP

Using $(POD_HOST_IP) we can then reference the environment variable elsewhere in the same deployment configuration. 然后,使用$(POD_HOST_IP)我们可以在同一部署配置中的其他位置引用环境变量。

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

相关问题 Kubernetes服务与部署中的一个Pod在一起吗? - Kubernetes service with exactly one pod from a deployment? kubernetes 是否在 pod 通过目标 pod 位于同一主机上的服务与 pod 通信时使用 conntrack 两次? - Does kubernetes use conntrack twice when a pod talks to a pod through a service where the destination pod is on the same host? Kubernetes + Socket.io:Pod 客户端 -&gt; LoadBalancer 服务 SSL 问题 - Kubernetes + Socket.io: Pod client -> LoadBalancer service SSL issues Kubernetes - 服务群集IP地址与Pod IP地址 - Kubernetes - service cluster IP address vs Pod IP address 如何在 kubernetes 的同一节点中为一项服务(同一 pod 的多个实例)联系一个随机 pod - How to contact a random pod for one service (mutli instance of the same pod) in the same node in kubernetes Pod 到 Pod 通信在 kubernetes 中不起作用 - Pod to Pod communication is not working in kubernetes 从 pod 到 Kubernetes 集群外的服务时,源 IP(记录在服务端,集群外)? - Source IP(recorded at service end, outside cluster) when talking from pod to a service outside Kubernetes cluster? Kubernetes Pod 中的 OpenVPN 客户端 - OpenVPN Client in Kubernetes Pod Kubernetes Pod随机超时 - Kubernetes pod random timeout kubernetes pod第二界面 - kubernetes pod second interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM