sidecar 容器

Kubernetes is an open-source container orchestration engine for automating deployment, scaling, and management of containerized applications. A pod is the basic building block of kubernetes application. Kubernetes manages pods instead of containers and pods encapsulate containers. A pod may contain one or more containers, storage, IP addresses, and, options that govern how containers should run inside the pod.

Kubernetes是一个开源容器编排引擎,用于自动化容器化应用程序的部署,扩展和管理。 Pod是kubernetes应用程序的基本构建块。 Kubernetes管理Pod而不是容器,并且Pod封装容器。 一个Pod可能包含一个或多个容器,存储,IP地址以及控制容器在Pod中运行方式的选项。

A pod that contains one container refers to a single container pod and it is the most common kubernetes use case. A pod that contains Multiple co-related containers refers to a multi-container pod. There are few patterns for multi-container pods one of them is the sidecar container pattern. In this post, we will see this pattern in detail with an example project.

包含一个容器的Pod是指单个容器Pod,这是最常见的kubernetes用例。 包含多个相互关联的容器的容器是指多容器容器。 用于多容器吊舱的模式很少,其中一种是边车集装箱模式。 在这篇文章中,我们将通过一个示例项目来详细了解这种模式。

  • What are Sidecar Containers

    什么是边车集装箱

  • Example Project

    示例项目

  • Test With Deployment Object

    使用部署对象进行测试

  • How to Configure Resource Limits

    如何配置资源限制

  • When should we use this pattern

    我们什么时候应该使用这种模式

  • Summary

    摘要

  • Conclusion

    结论

什么是边车集装箱 (What are Sidecar Containers)

Sidecar containers are the containers that should run along with the main container in the pod. This sidecar pattern extends and enhances the functionality of current containers without changing it. Nowadays, We know that we use container technology to wrap all the dependencies for the application to run anywhere. A container does only one thing and does that thing very well.

Sidecar容器是应与吊舱中的主容器一起运行的容器。 这种Sidecar模式在不更改它的情况下扩展并增强了当前容器的功能。 如今,我们知道我们使用容器技术来包装所有依赖项,以便应用程序可以在任何地方运行。 容器只做一件事情,并且做得很好。

Imagine that you have the pod with a single container working very well and you want to add some functionality to the current container without touching or changing, how can you add the additional functionality or extending the current functionality? This sidecar container pattern really helps exactly in that situation.

想象一下,您的带有单个容器的容器运行得很好,并且您想在不触摸或更改的情况下向当前容器添加一些功能,如何添加其他功能或扩展当前功能? 在这种情况下,这种边车集装箱模式确实可以提供帮助。

Sidecar Container Pattern边车集装箱模式

If you look at the above diagram, you can define any number of containers for Sidecar containers and your main container works along with it successfully. All the Containers will be executed parallelly and the whole functionality works only if both types of containers are running successfully. Most of the time these sidecar containers are simple and small that consume fewer resources than the main container.

如果您查看上面的图,则可以为Sidecar容器定义任意数量的容器,并且您的主容器可以成功与之协同工作。 所有容器将并行执行,并且仅当两种类型的容器都成功运行时,整个功能才起作用。 在大多数情况下,这些边车容器既简单又小巧,比主容器消耗更少的资源。

示例项目 (Example Project)

Let’s implement a simple project to understand this pattern. Here is a simple pod that has main and sidecar containers. The main container is nginx serving on the port 80 that takes the index.html from the volume mount workdir location. The Sidecar container with the image busybox creates logs in the same location with a timestamp. Since the Sidecar container and main container runs parallel Nginx will display the new log information every time you hit in the browser.

让我们实现一个简单的项目来理解这种模式。 这是一个简单的吊舱,有主箱和小车箱。 主要容器是nginx,它在端口80上提供服务,该端口从卷装载工作目录位置获取index.html。 带有图像busybox的Sidecar容器在带有时间戳的相同位置创建日志。 由于Sidecar容器和主容器并行运行,因此Nginx每次在浏览器中命中都会显示新的日志信息。

pod.yamlpod.yaml
// create the podkubectl create -f pod.yml// list the podskubectl get po// exec into podkubectl exec -it sidecar-container-demo -c main-container -- /bin/sh# apt-get update && apt-get install -y curl# curl localhost

You can install curl and query the localhost and check the response.

您可以安装curl和查询localhost并检查响应。

Testing Sidecar Container测试Sidecar集装箱

使用部署对象进行测试 (Test With Deployment Object)

Let’s create a deployment object with the same pod specification with 5 replicas. I have created a service with the port type NodePort so that we can access the deployment from the browser. Pods are dynamic here and the deployment controller always tries to maintain the desired state that’s why you can’t have one static IP Address to access the pods so that you have to create a service that exposes the static port to the outside world. Internally service maps to the port 80 based on the selectors. You will see that in action in a while.

让我们创建具有5个副本的相同pod规范的部署对象。 我已经创建了端口类型为NodePort的服务,以便我们可以从浏览器访问部署。 Pod在这里是动态的,并且部署控制器始终尝试保持所需的状态,这就是为什么您无法使用一个静态IP地址来访问Pod的原因,因此必须创建一个将静态端口暴露给外界的服务。 内部服务根据选择器映射到端口80。 您会在一段时间内看到它的作用。

Deployment部署方式

Let’s look at the below deployment object where we define one main container and two sidecar containers. All the containers run in parallel. The two sidecar containers create logs in the location /var/log. The main container Nginx serves those log files as when we hit the NGINX web server from the port 80. You will see that in action in a while.

让我们看一下下面的部署对象,其中定义了一个主容器和两个sidecar容器。 所有容器并行运行。 两个sidecar容器在/ var / log位置中创建日志。 当我们从端口80进入NGINX Web服务器时,主容器Nginx提供了这些日志文件。您将在一段时间内看到它的作用。

manifest.ymlmanifest.yml

Let’s follow these commands to test the deployment.

让我们按照以下命令测试部署。

// create a deploymentkubectl create -f manifest.yml// list the deployment, pods, and servicekubectl get deploy -o widekubectl get po -o widekubectl get svc -o wide
deployment in action实际部署

In the above diagram, You can see 5 pods running in different IP addresses and the service object maps the port 32123 to the port 80. You can actually access this deployment from the browser from the kubernetes master IP address 192.168.64.2 and the service port 32123.

在上图中,您可以看到5个Pod在不同的IP地址中运行,并且服务对象将端口32123映射到端口80 。 实际上,您可以从浏览器通过kubernetes主IP地址192.168.64.2和服务端口32123访问此部署。

http://192.168.64.2:32123

You can even test the pod with the following commands

您甚至可以使用以下命令测试广告连播

// exec into main container of the podkubectl exec -it nginx-webapp-7c8b4d4f8d-9qmdm -c main-container -- /bin/sh// install curl# apt-get update && apt-get install -y curl# curl localhost
Sidecar Pattern in action边车模式在行动

如何配置资源限制 (How to Configure Resource Limits)

Configuring resource limits is very important when it comes to Sidecar containers. The main point we need to understand here is All the containers run in parallel so when you configure resource limits for the pod you have to take that into consideration.

对于Sidecar容器,配置资源限制非常重要。 我们在这里需要了解的要点是所有容器都是并行运行的,因此在为容器配置资源限制时,必须考虑到这一点。

  • The sum of all the resource limits of the main containers as well as sidecar containers (Since all the containers run in parallel)主容器和边车容器的所有资源限制的总和(因为所有容器并行运行)

我们什么时候应该使用这种模式 (When should we use this pattern)

These are some of the scenarios where you can use this pattern

在某些情况下,您可以使用此模式

  • Whenever you want to extend the functionality of the existing single container pod without touching the existing one.每当您想扩展现有单个容器吊舱的功能而无需接触现有容器吊舱时。
  • Whenever you want to enhance the functionality of the existing single container pod without touching the existing one.每当您想增强现有单个容器容器的功能而又不触及现有容器容器的情况时。
  • You can use this pattern to synchronize the main container code with the git server pull.您可以使用此模式将主容器代码与git服务器请求同步。
  • You can use this pattern for sending log events to the external server.您可以使用此模式将日志事件发送到外部服务器。
  • You can use this pattern for network-related tasks.您可以将此模式用于与网络相关的任务。

摘要 (Summary)

  • A pod that contains one container refers to a single container pod and it is the most common kubernetes use case.包含一个容器的Pod是指单个容器Pod,这是最常见的kubernetes用例。
  • A pod that contains Multiple co-related containers refers to a multi-container pod.包含多个相互关联的容器的容器是指多容器容器。
  • The Sidecar container pattern is one of the patterns that we use regularly for extending or enhancing pre-existing containers.Sidecar容器模式是我们经常用来扩展或增强现有容器的模式之一。
  • Sidecar containers run in parallel with the main container. So that you need to consider resource limits of sidecar containers while defining request/resource limits for the pod.边车集装箱与主集装箱平行运行。 因此,在定义吊舱的请求/资源限制时,您需要考虑Sidecar容器的资源限制。
  • The application containers and Sidecar containers run-in parallel which means all the containers run at the same time. So that you need to sum up all the request/resource limits of the containers while defining request/resource limits for the pod.应用程序容器和Sidecar容器并行运行,这意味着所有容器都同时运行。 因此,您需要在定义容器的请求/资源限制时总结容器的所有请求/资源限制。
  • You should configure health checks for sidecar containers as main containers to make sure they are healthy.您应将边车容器配置为主要容器的运行状况检查,以确保它们是健康的。
  • All the pods in the deployment object don’t have static IP addresses so that you need a service object to expose to the outside world.部署对象中的所有Pod没有静态IP地址,因此您需要一个服务对象才能向外界公开。
  • The service object internally maps to the port container port based on the selectors.服务对象根据选择器在内部映射到端口容器端口。
  • You can use this pattern where your application or main containers need extending or enhancing the current functionality.您可以在应用程序或主容器需要扩展或增强当前功能的地方使用此模式。

结论 (Conclusion)

It’s always to good to know already proven kubernetes patterns. Make sure all your sidecar containers are simple and small enough because you have to sum up all the resources/request limits while defining resource limits for the pod. You need to make sure Sidecar containers are also healthy by configuring health checks. So it’s important to know when to combine your functionality into the main container or have a separate container.

知道已经证明的kubernetes模式总是很高兴。 确保所有sidecar容器都足够简单且足够小,因为在定义容器的资源限制时,您必须总结所有资源/请求限制。 您需要通过配置运行状况检查来确保Sidecar容器也正常。 因此,重要的是要知道何时将您的功能组合到主容器中或拥有一个单独的容器。

翻译自: https://medium.com/bb-tutorials-and-thoughts/kubernetes-learn-sidecar-container-pattern-6d8c21f873d

sidecar 容器


http://www.taodudu.cc/news/show-3744257.html

相关文章:

  • 云管边端架构图_车路协同的云管边端架构及服务研究
  • 边车设计模式-Sidecar pattern
  • 分布式系统治理-边车模式 sidecar
  • 分布式服务之边车模式
  • ServiceMesh的关键:边车模式(sidecar);又要开车了
  • 转载 -- 边车模式(sidecar)和服务网格(server mesh)
  • istio学习笔记2:边车模式sidecar
  • 分布式设计之边车模式(Sidecar)
  • hanlp句法分析
  • 斯坦福句法分析 java_斯坦福句法分析
  • 斯坦福句法分析 java_斯坦福句法分析使用方法(java版)
  • 斯坦福句法分析 java_使用stanford nlp进行依存句法分析
  • 【白话NLP】——依存句法分析
  • 自然语言处理NLP(8)——句法分析b:完全句法分析
  • Linux 输出流重定向缓冲设置
  • Linux输出重定向与追加
  • linux输出重定向命令
  • Linux输出重定向:>与>>
  • Linux 输出的重定向
  • linux的输出重定向
  • Linux C 输入输出重定向
  • Linux 输出重定向说明
  • Linux输出重定向 文件 21
  • Linux输入/输出重定向
  • linux输出重定向和输入重定向
  • Linux-输入输出重定向
  • linux文件输入输出的重定向
  • Linux输出重定向 >> 文件 2>1
  • linux shell重定向(输入输出重定向)讲解
  • linux标准输出重定向到文件夹,linux输入输出重定向使用详解

sidecar 容器_kubernetes学习sidecar容器模式相关推荐

  1. 印象大使_kubernetes学习大使容器模式

    印象大使 Kubernetes is an open-source container orchestration engine for automating deployment, scaling, ...

  2. Docker学习:容器五种(3+2)网络模式 | bridge模式 | host模式 | none模式 | container 模式 | 自定义网络模式详解

    前言 本讲是从Docker系列讲解课程,单独抽离出来的一个小节,重点介绍容器网络模式, 属于了解范畴,充分了容器的网络模式,更有助于更好的理解Docker的容器之间的访问逻辑. 疑问:为什么要了解容器 ...

  3. pause容器作用_Kubernetes学习之pause容器

    根据代码看到,pause容器运行着一个非常简单的进程,它不执行任何功能,一启动就永远把自己阻塞住了, 它的作用就是扮演PID1的角色,并在子进程称为"孤儿进程"的时候,通过调用wa ...

  4. java 容器_Java容器框架学习整理

    一:容器框架概述 1.什么是容器 2.Java 中的容器 二:Collectoin 容器 1.Collection 接口定义 2.Collection 三个重要的子接口 List.Set.Queue ...

  5. 不会和容器一起启动_一起学习docker05-docker容器

    一起来学docker系列: 一起学docker-可视化管理01-Portainer 一起学docker-可视化管理02-Rancher 一起学习docker01-docker简介和安装 一起学习doc ...

  6. doker学习4---docker容器数据卷

    doker学习4-docker容器数据卷 一.Docker容器数据卷是什么? 先来看看Docker的理念: 将运用与运行的环境打包形成容器运行 ,运行可以伴随着容器,但是我们对数据的要求希望是持久化的 ...

  7. Docker、Podman 容器“扫盲“ 学习笔记【与云原生的故事】

    [摘要] 笔记内容:由理论和具体docker常用操作构成.这篇博文笔记的定位是:温习,查阅,不适合新手学习.你拥有青春的时候,就要感受它,不要虚掷你的黄金时代,不要去倾听... 写在前面 笔记内容:由 ...

  8. Docker、Podman 容器“扫盲“ 学习笔记

    写在前面 之前只是做毕业设计时,接触一点,用DockFile在阿里云上部署了毕设.后来docker端口问题,机器被植入木马,拉去挖矿,cup天天爆满,百度半天删了好多文件不管用,后来恢复镜像了,之后在 ...

  9. 【Docker】容器的几种网络模式

    当你使用Docker时,你会发现需要了解很多关于网络的知识.Docker作为目前最火的轻量级容器引擎,因此,我们有必要深入了解Docker的网络知识,以满足更高的网络需求.本文介绍了Docker的4种 ...

最新文章

  1. Hadoop- MapReduce分布式计算框架原理
  2. debian清除无用的库文件(清理系统,洁癖专用)
  3. python正则表达式,看完这篇文章就够了...
  4. STM32----摸石头过河系列(七)
  5. Java高级语法笔记-普通异常处理
  6. nodejs实践录:基于koa的简单web服务器
  7. Algorithm:位运算的这些小技巧你知道吗?
  8. 社区团购会一直走下去吗?
  9. Framework7——基础工具类
  10. java基于springboot小说下载网站管理系统源码
  11. 关于相机(摄相头)的选用
  12. 计算机组成原理第二版第6章ppt,计算机组成原理第6章简.ppt
  13. 对偶式与反函数_函数Y =A(B+C)的对偶式Y’= 和反函数`Y=
  14. jquery之empty()方法详解
  15. 一行代码卖出570美元, 天价代码的内幕
  16. STM32单片机烧录失败汇总
  17. sort按vector元素排序
  18. JVM致命错误日志(hs_err_pid.log)解读
  19. python中哪些是无序_关于无序集合:无序集合 – 在python中设置
  20. 【Python】《点燃我,温暖你》,快来Get李峋同款爱心代码

热门文章

  1. uniapp 开发小程序购物车
  2. TypeScript error in....node_modules/@types/babel__traverse/index.d.ts(68,50):
  3. php网站漏洞大全,Webvulscan:一款基于PHP的漏洞扫描器
  4. 在王者荣耀角度下分析面向对象程序设计B中23种设计模式之适配器模式
  5. Scade——学习笔记(3)
  6. 服务器新增硬盘不显示,dell服务器已有阵列新增的磁盘无法识别显示外来
  7. 最近几天心情比较低落
  8. GLEW 1.3.5 adds OpenGL 2.1 and NVIDIA G80 extensions
  9. matlab 取余(rem)和取模(mod)的区别
  10. 工程研发专业名词解释(EVT,DVT,DMT,MVT,PVT,MP)