简体   繁体   English

如何在Kubernetes pods内“水平”组织容器?

[英]How to organize containers “horizontally” inside Kubernetes pods?

So I'm trying to wrap my head around what exactly a typical Kubernetes pod looks like. 所以我试图围绕一个典型的Kubernetes pod看起来像什么。 According to their docs , a pod : 根据他们的文档 ,一个pod

" A pod (as in a pod of whales or pea pod) corresponds to a colocated group of applications running with a shared context. " 一个pod(如在一群鲸鱼或豌豆荚中)对应于一个以共享上下文运行的共同应用程序组。

Later in that same article: 后来在同一篇文章中:

" Pods can be used to host vertically integrated application stacks, but their primary motivation is to support co-located... " Pod可用于托管垂直集成的应用程序堆栈,但它们的主要动机是支持共存......

OK, so you can organize a single pod as your entire vertical stack (from DB to web app). 好的,您可以将单个窗格组织为整个垂直堆栈(从数据库到Web应用程序)。 But apparently that's not typically how it's organized, so I assume that typically a " horizontal " organization is preferred ( why?? ). 但显然这通常不是它的组织方式,所以我认为通常一个“ 横向 ”组织是首选( 为什么?? )。

But to me, horizontal layering/stratification implies that you'll only have one container in a pod, because typically in each tier of service (web, app, cache, db, etc.) you'll have one type of component. 但对我来说,水平分层/分层意味着你在一个pod中只有一个容器,因为通常在每个服务层(web,app,cache,db等)中你都有一种类型的组件。

Let's take a concrete example. 我们举一个具体的例子。 Say we have the following vertical stack of tiers: 假设我们有以下垂直堆栈:

  • Web frontend containers; Web前端容器; Grails or Spring MVC web/app server Grails或Spring MVC web / app服务器
  • Microservices containers; 微服务容器; RESTful web services where core business logic lives RESTful Web服务,其中包含核心业务逻辑
  • Message broker (say RabbitMQ) containers 消息代理(比如RabbitMQ)容器
  • Microservice cache (some services have distributed Hazelcast cache clusters sitting between them and their DB/backing store) containers 微服务缓存(一些服务已经分布了位于它们之间的Hazelcast缓存集群及其DB /后备存储)容器
  • MySQL DB cluster containers MySQL数据库集群容器
  • MongoDB cluster containers MongoDB集群容器
  • 3rd party RESTful cloud API (say SalesForce or Stripe or something similar) 第三方RESTful云API(比如SalesForce或Stripe或类似的东西)

These are fairly typical components in an app stack. 这些是应用程序堆栈中相当典型的组件。 If we went against Kubernetes' own advice, and created "vertically-aligned" pods, each pod would consist of 1 type of container for each tier (the web/app server, each microservice, each DB, etc.). 如果我们反对Kubernetes自己的建议,并创建“垂直对齐”的pod,每个pod将由每层的一种类型的容器(web / app服务器,每个微服务,每个DB等)组成。

But how would a horizontally-aligned pod be organized? 但是如何组织水平对齐的吊舱呢? What containers would go in which pods? 什么容器会进入哪个容器?

A Pod is the basic scheduling unit in Kubernetes. Pod是Kubernetes的基本调度单元。 It is the common case that a pod will only have a single container running in it, as most containers can be scheduled independently (ie they do not need to be co-located on the same machine). 通常情况下,pod只有一个容器在其中运行,因为大多数容器可以独立调度(即它们不需要共同位于同一台机器上)。

With regards to your example, you could put most containers in individual pods, and use a Replication Controller to horizontally scale the number of replicas of each Pod (and therefore container) as needed. 关于您的示例,您可以将大多数容器放在单个pod中,并使用Replication Controller根据需要水平扩展每个Pod(以及容器)的副本数。 Along with your replication controller, you'll also want a Service to load balance between the replicas. 与复制控制器一起,您还需要服务在副本之间进行负载平衡。 Vertical tiers could be organized using labels on the pods/replication controllers/services, such as tier=message_broker . 可以使用pod /复制控制器/服务上的标签来组织垂直层,例如tier=message_broker

Edit: 编辑:

The reason it's not a good idea to put your entire stack in a single pod is it limits your flexibility: 将整个堆栈放在一个pod中并不是一个好主意的原因是它限制了你的灵活性:

  • It forces your entire stack to be scheduled on a single machine, which could make scheduling more difficult if machines lack some of the necessary resources. 它会强制您在整个计算机上安排整个堆栈,如果计算机缺少某些必要的资源,这可能会使计划更加困难。
  • Individual components cannot be scaled independently (eg if you need more frontend replicas to handle traffic, but your DB is only used for a small number of queries) 单个组件无法独立扩展(例如,如果您需要更多前端副本来处理流量,但您的数据库仅用于少量查询)
  • All the containers would need to agree on which ports to use. 所有容器都需要就要使用的端口达成一致。 Each pod has a unique IP, so containers running in separate pods can use the same ports. 每个pod都有一个唯一的IP,因此在不同的pod中运行的容器可以使用相同的端口。

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

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