You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/zh-cn/blog/_posts/2025-04-22-multicontainer-patterns/index.md
+29-31Lines changed: 29 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,17 @@
1
1
---
2
2
layout: blog
3
3
title: "Kubernetes 多容器 Pod:概述"
4
-
date: 2025-04-15
5
-
draft: true
4
+
date: 2025-04-22
5
+
draft: false
6
6
slug: multi-container-pods-overview
7
7
author: Agata Skorupka (The Scale Factory)
8
8
translator: Xin Li (Daocloud)
9
9
---
10
-
11
10
<!--
12
11
layout: blog
13
12
title: "Kubernetes Multicontainer Pods: An Overview"
14
-
date: 2025-04-15
15
-
draft: true
13
+
date: 2025-04-22
14
+
draft: false
16
15
slug: multi-container-pods-overview
17
16
author: Agata Skorupka (The Scale Factory)
18
17
-->
@@ -22,15 +21,15 @@ As cloud-native architectures continue to evolve, Kubernetes has become the go-t
22
21
-->
23
22
随着云原生架构的不断演进,Kubernetes 已成为部署复杂分布式系统的首选平台。
24
23
在这个生态系统中,最强大却又微妙的设计模式之一是边车(Sidecar)
25
-
模式 —— 一种允许开发者扩展应用程序功能而不深入源代码的技术。
24
+
模式 —— 一种允许开发者扩展应用功能而不深入源代码的技术。
26
25
27
26
<!--
28
27
## The origins of the sidecar pattern
29
28
30
29
Think of a sidecar like a trusty companion motorcycle attachment. Historically, IT infrastructures have always used auxiliary services to handle critical tasks. Before containers, we relied on background processes and helper daemons to manage logging, monitoring, and networking. The microservices revolution transformed this approach, making sidecars a structured and intentional architectural choice.
31
30
With the rise of microservices, the sidecar pattern became more clearly defined, allowing developers to offload specific responsibilities from the main service without altering its code. Service meshes like Istio and Linkerd have popularized sidecar proxies, demonstrating how these companion containers can elegantly handle observability, security, and traffic management in distributed systems.
32
31
-->
33
-
## 边车模式的起源
32
+
## 边车模式的起源 {#the-origins-of-the-sidecar-pattern}
34
33
35
34
想象一下边车就像一个可靠的伴侣摩托车附件。历史上,IT 基础设施总是使用辅助服务来处理关键任务。
36
35
在容器出现之前,我们依赖后台进程和辅助守护程序来管理日志记录、监控和网络。
@@ -50,11 +49,10 @@ native support for sidecars.
50
49
Sidecar containers can now be defined within a Pod manifest using the `spec.initContainers` field. What makes
51
50
it a sidecar container is that you specify it with `restartPolicy: Always`. You can see an example of this below, which is a partial snippet of the full Kubernetes manifest:
That field name, `spec.initContainers` may sound confusing. How come when you want to define a sidecar container, you have to put an entry in the `spec.initContainers` array? `spec.initContainers` are run to completion just before main application starts, so they’re one-off, whereas sidecars often run in parallel to the main app container. It’s the `spec.initContainers` with `restartPolicy:Always` which differs classic [init containers](/docs/concepts/workloads/pods/init-containers/) from Kubernetes-native sidecar containers and ensures they are always up.
While the sidecar pattern can be useful in many cases, it is generally not the preferred approach unless the use case justifies it. Adding a sidecar increases complexity, resource consumption, and potential network latency. Instead, simpler alternatives such as built-in libraries or shared infrastructure should be considered first.
@@ -103,7 +101,7 @@ While the sidecar pattern can be useful in many cases, it is generally not the p
103
101
-->
104
102
**在以下情况部署边车:**
105
103
106
-
1. 你需要扩展应用程序功能,而无需修改原始代码
104
+
1. 你需要扩展应用功能,而无需修改原始代码
107
105
1. 实现日志记录、监控或安全等跨领域关注点
108
106
1. 处理需要现代网络功能的遗留应用
109
107
1. 设计需要独立扩展和更新的微服务
@@ -130,12 +128,12 @@ While the sidecar pattern can be useful in many cases, it is generally not the p
130
128
131
129
The **Init container** pattern is used to execute (often critical) setup tasks before the main application container starts. Unlike regular containers, init containers run to completion and then terminate, ensuring that preconditions for the main application are met.
@@ -154,15 +152,15 @@ The init container ensures your application starts in a predictable, controlled
154
152
1. 验证依赖项的可用性
155
153
1. 运行数据库迁移
156
154
157
-
初始化容器确保你的应用程序在一个可预测、受控的环境中启动,而无需修改代码。
155
+
Init 容器确保你的应用在一个可预测、受控的环境中启动,而无需修改代码。
158
156
159
157
<!--
160
158
### Ambassador pattern
161
159
162
160
An ambassador container provides Pod-local helper services that expose a simple way to access a network service. Commonly, ambassador containers send network requests on behalf of a an application container and
163
161
take care of challenges such as service discovery, peer identity verification, or encryption in transit.
164
162
-->
165
-
### Ambassador 模式
163
+
### Ambassador 模式 {#ambassador-pattern}
166
164
167
165
一个大使(Ambassador)容器提供了 Pod 本地的辅助服务,这些服务暴露了一种访问网络服务的简单方式。
@@ -188,11 +186,11 @@ take care of challenges such as service discovery, peer identity verification, o
188
186
A _configuration helper_ sidecar provides configuration updates to an application dynamically, ensuring it always has access to the latest settings without disrupting the service. Often the helper needs to provide an initial
189
187
configuration before the application would be able to start successfully.
190
188
-->
191
-
### 配置助手
189
+
### 配置助手 {#configuration-helper}
192
190
193
-
一个**配置助手**边车容器动态地向应用程序提供配置更新,
191
+
一个**配置助手**边车容器动态地向应用提供配置更新,
194
192
确保它始终可以访问最新的设置而不会中断服务。
195
-
通常,助手需要在应用程序能够成功启动之前提供初始配置。
193
+
通常,助手需要在应用能够成功启动之前提供初始配置。
196
194
197
195
<!--
198
196
**Use cases:**
@@ -205,16 +203,16 @@ configuration before the application would be able to start successfully.
205
203
206
204
1. 获取环境变量和密钥
207
205
1. 轮询配置更改
208
-
1. 将配置管理与应用程序逻辑解耦
206
+
1. 将配置管理与应用逻辑解耦
209
207
210
208
<!--
211
209
### Adapter pattern
212
210
213
211
An _adapter_ (or sometimes _façade_) container enables interoperability between the main application container and external services. It does this by translating data formats, protocols, or APIs.
@@ -237,7 +235,7 @@ While sidecar patterns offer tremendous flexibility, they're not a silver bullet
237
235
The key is strategic implementation: use sidecars as precision tools to solve specific architectural challenges, not as a default approach. When used correctly, they can improve security, networking, and configuration management in containerized environments.
238
236
Choose wisely, implement carefully, and let your sidecars elevate your container ecosystem.
0 commit comments