Kubernetes中的Pod:为何不可或缺

需积分: 0 0 下载量 148 浏览量 更新于2024-08-05 收藏 899KB PDF 举报
"13 _ 为什么我们需要Pod?1" 在Kubernetes(K8s)生态系统中,Pod是一个至关重要的概念。Pod被定义为Kubernetes中的最小可调度单元,它代表了一个或多个紧密相关的容器的集合。Pod提供了一种封装,使得这些容器能够共享存储卷和网络资源,这在传统的容器模型中是无法实现的。Pod的设计初衷是为了满足在集群环境中管理和协调容器的需求。 首先,理解Pod的重要性,我们要回顾容器的本质。容器本质上是进程的隔离实例,它们通过Namespace实现命名空间的隔离,用Cgroups进行资源限制,并依赖rootfs提供独立的文件系统视图。然而,单个容器虽然能很好地隔离和封装应用,但在实际部署和管理时,往往需要考虑多个容器协同工作的情况,例如,一个应用可能包含前端服务和后台数据库,这两个组件需要共享数据存储和网络端口。 这就是Pod的价值所在。在一个Pod内,多个容器可以共享同一个网络IP和端口,这意味着它们对外部看起来像是运行在同一主机上的进程,这简化了服务发现和通信。此外,Pod内的容器还可以共享存储卷,允许持久化数据在容器重启后仍然保留,解决了容器无状态性的局限。 Kubernetes作为容器编排系统,其目标是构建一个类似操作系统的层来管理容器化的应用程序。就像在操作系统中,进程是基本的执行单元,而在Kubernetes中,Pod扮演了类似的角色。Pod的生命周期、扩展性和弹性都由Kubernetes控制器来管理,这使得开发者和运维人员能够专注于应用逻辑,而不必过于关注底层基础设施的细节。 当我们创建一个Pod时,会定义一组配置,包括容器的镜像、资源限制、环境变量等。Kubernetes根据这些配置启动和管理Pod内的容器。Pod还有复制集(ReplicaSet)或部署(Deployment)等控制器来确保特定数量的Pod副本始终可用,从而实现了高可用性。 Pod的另一个重要特性是它支持滚动更新。当应用需要升级时,Kubernetes可以逐步替换Pod的实例,确保服务的连续性和稳定性。此外,通过Pod模板,可以轻松地扩展应用,只需更改模板即可创建新的Pod实例。 总结来说,Pod是Kubernetes中不可或缺的组成部分,它提供了在集群中管理和协调多容器应用的机制,实现了容器间的资源共享和通信,以及服务的高可用和可扩展性。Pod的存在使得Kubernetes能够作为一个强大的容器编排平台,有效地支撑现代云原生应用的部署和运维。

解释代码void LedOn(GPIO_Module* GPIOx, uint16_t Pin) { GPIOx->PBSC = Pin; } /** * @brief Turns selected Led Off. * @param GPIOx x can be A to G to select the GPIO port. * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. */ void LedOff(GPIO_Module* GPIOx, uint16_t Pin) { GPIOx->PBC = Pin; } /** * @brief Turns selected Led on or off. * @param GPIOx x can be A to G to select the GPIO port. * @param Pin This parameter can be one of the following values: * @arg GPIO_PIN_0~GPIO_PIN_15: set related pin on * @arg (GPIO_PIN_0<<16)~(GPIO_PIN_15<<16): clear related pin off */ void LedOnOff(GPIO_Module* GPIOx, uint32_t Pin) { GPIOx->PBSC = Pin; } /** * @brief Toggles the selected Led. * @param GPIOx x can be A to G to select the GPIO port. * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15. */ void LedBlink(GPIO_Module* GPIOx, uint16_t Pin) { GPIOx->POD ^= Pin; } /** * @brief Assert failed function by user. * @param file The name of the call that failed. * @param line The source line number of the call that failed. */ #ifdef USE_FULL_ASSERT void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line) { while (1) { } } #endif // USE_FULL_ASSERT /** * @brief Main program. */ int main(void) { /*SystemInit() function has been called by startup file startup_n32g45x.s*/ /* Initialize Led1~Led5 as output pushpull mode*/ LedInit(PORT_GROUP1, LED1_PIN | LED2_PIN); LedInit(PORT_GROUP2, LED3_PIN | LED4_PIN | LED5_PIN); /*Turn on Led1*/ LedOn(PORT_GROUP1, LED1_PIN); while (1) { /*LED1_PORT and LED2_PORT are the same port group.Enable Led2 blink and not effect Led1 by Exclusive-OR * operation.*/ LedBlink(PORT_GROUP1, LED2_PIN); /*LED3_PORT, LED4_PORT and LED5_PORT are the same port group.*/ /*Turn Led4 and Led5 off and not effect other ports by PBC register,correspond to * PORT_GROUP2->POD&=~(LED4_PIN|LED5_PIN);*/ LedOff(PORT_GROUP2, LED4_PIN | LED5_PIN); /* Insert delay */ Delay(0x28FFFF); /*Turn Led4 and Led5 on,turn Led3 off and not effect other ports by PBSC register,correspond to * PORT_GROUP2->POD&=~(LED3_PIN),then PORT_GROUP2->POD|=(LED4_PIN|LED5_PIN);*/ LedOnOff(PORT_GROUP2, (LED3_PIN << 16) | LED4_PIN | LED5_PIN); /* Insert delay */ Delay(0x28FFFF); /*Turn on Led3*/ LedOn(PORT_GROUP2, LED3_PIN); /* Insert delay */ Delay(0x28FFFF); } }

2023-07-14 上传
2023-07-13 上传

Jul 13 00:48:29 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: Unit docker.service entered Jul 13 00:48:29 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: docker.service failed. Jul 13 00:48:32 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: docker.service holdoff time Jul 13 00:48:32 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: Stopped Docker Application C -- Subject: Unit docker.service has finished shutting down -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit docker.service has finished shutting down. Jul 13 00:48:32 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: start request repeated too q Jul 13 00:48:32 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: Failed to start Docker Appli -- Subject: Unit docker.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit docker.service has failed. -- -- The result is failed. Jul 13 00:48:32 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: Unit docker.service entered Jul 13 00:48:32 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: docker.service failed. Jul 13 00:50:01 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: Started Session 1145949 of u -- Subject: Unit session-1145949.scope has finished start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit session-1145949.scope has finished starting up. -- -- The start-up result is done. Jul 13 00:50:01 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f CROND[308]: (root) CMD (/usr/lib64/sa/sa

2023-07-13 上传

-- Logs begin at Thu 2023-07-13 00:44:15 CST, end at Thu 2023-07-13 00:53:06 CST. -- Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f systemd[1]: Starting Docker Application Container Engine... Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: time="2023-07-13T00:48:25.388440905+08:00" level=info msg="Starting up" Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: time="2023-07-13T00:48:25.405370737+08:00" level=error msg="failed to mount overlay: invalid argument" storage-driver=overlay2 Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: time="2023-07-13T00:48:25.408339784+08:00" level=info msg="Loading containers: start." Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: time="2023-07-13T00:48:25.409506558+08:00" level=warning msg="Running modprobe bridge br_netfilter failed with message: , error: exit status 1" Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: time="2023-07-13T00:48:25.411850508+08:00" level=info msg="unable to detect if iptables supports xlock: 'iptables --wait -L -n': `iptables v1.4.21: can't initialize iptables table `filter': Permission denied (you must be root)\nPerhaps iptables or your kernel needs to be upgraded.`" error="exit status 3" Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: time="2023-07-13T00:48:25.425371913+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby Jul 13 00:48:25 pod-64788377f624725f6ea4b9e8-64aed85ec2dbab11bceeb07f dockerd[215]: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.4.21: can't initialize iptables table `nat': Permission denied (you must be root)

2023-07-13 上传