Pods are the smallest deployable units of computing that can be created and managed in Kubernetes.php
A pod (as in a pod of whales or pea pod) is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers. A pod’s contents are always co-located and co-scheduled, and run in a shared context. A pod models an application-specific “logical host” - it contains one or more application containers which are relatively tightly coupled — in a pre-container world, they would have executed on the same physical or virtual machine.html
While Kubernetes supports more container runtimes than just Docker, Docker is the most commonly known runtime, and it helps to describe pods in Docker terms.node
The shared context of a pod is a set of Linux namespaces, cgroups, and potentially other facets of isolation - the same things that isolate a Docker container. Within a pod’s context, the individual applications may have further sub-isolations applied.linux
Containers within a pod share an IP address and port space, and can find each other via localhost
. They can also communicate with each other using standard inter-process communications like SystemV semaphores or POSIX shared memory. Containers in different pods have distinct IP addresses and can not communicate by IPC without special configuration. These containers usually communicate with each other via Pod IP addresses.git
一个Pod中的容器共享IP地址和端口空间,可使用localhost通讯。还可使用标准inter-process 通讯,好比System V semaphores或POSIX共享内存。不一样Pods上的容器的IP地址不一样,不能直接用IPC通讯,除非进行特殊设置。这些容器可使用Pod IP地址通讯。github
Applications within a pod also have access to shared volumes, which are defined as part of a pod and are made available to be mounted into each application’s filesystem.web
In terms of Docker constructs, a pod is modelled as a group of Docker containers with shared namespaces and shared volumes.docker
Like individual application containers, pods are considered to be relatively ephemeral (rather than durable) entities. As discussed in life of a pod, pods are created, assigned a unique ID (UID), and scheduled to nodes where they remain until termination (according to restart policy) or deletion. If a node dies, the pods scheduled to that node are scheduled for deletion, after a timeout period. A given pod (as defined by a UID) is not “rescheduled” to a new node; instead, it can be replaced by an identical pod, with even the same name if desired, but with a new UID (see replication controller for more details).apache
When something is said to have the same lifetime as a pod, such as a volume, that means that it exists as long as that pod (with that UID) exists. If that pod is deleted for any reason, even if an identical replacement is created, the related thing (e.g. volume) is also destroyed and created anew.bootstrap
Pod内的全部应用均可以使用共享volumes,共享volumes是做为Pod的一部分,每一个应用的文件系统上都被挂载了。
以Docker为例,pod做为docker容器的模型,共享了namespaces和shared volumes。
每一个Pod在被建立时,都被赋值了一个unique ID(UID)
若是说某个东西的生命周期和pod相同,好比volume,意思是只要pod存在,这个东西就存在。若是pod被删除了,即便出现了相同的替代pod,这个东西也会被消耗重建。
A multi-container pod that contains a file puller and a web server that uses a persistent volume for shared storage between the containers.
闪图是一个多容器pod,包含一个file puller和一个web server,在容器之间使用persistent volume用来共享存储。
Pods are a model of the pattern of multiple cooperating processes which form a cohesive unit of service. They simplify application deployment and management by providing a higher-level abstraction than the set of their constituent applications. Pods serve as unit of deployment, horizontal scaling, and replication. Colocation (co-scheduling), shared fate (e.g. termination), coordinated replication, resource sharing, and dependency management are handled automatically for containers in a pod.
Pod是一种将多个相互协做的进程组成聚合的服务单元的模型,经过提供对多个应用的多个抽象,简化了应用的部署和管理。Pod是做为部署、水平扩展、副本的管理单元。Pod中的多个容器相互写做、共享生命周期、副本一致、资源共享、依赖管理等功能都是自动由Pod管理的。
Pods enable data sharing and communication among their constituents.
The applications in a pod all use the same network namespace (same IP and port space), and can thus “find” each other and communicate using localhost
. Because of this, applications in a pod must coordinate their usage of ports. Each pod has an IP address in a flat shared networking space that has full communication with other physical computers and pods across the network.
The hostname is set to the pod’s Name for the application containers within the pod. More details on networking.
In addition to defining the application containers that run in the pod, the pod specifies a set of shared storage volumes. Volumes enable data to survive container restarts and to be shared among the applications within the pod.
Pod中的多个应用共享数据和通讯资源。
一个Pod中的全部应用使用相同的网络空间(IP和port域),可使用localhost相互通讯。所以一个pod中的应用必须协商ports的使用。每一个pod都有一个IP地址,能够与网络中的其余物理机和pods相互通讯。
pod的hostname就是pod的名称。
pod能够设置一些shared storage volumnes,容许容器重启后读取服务,容器间共享数据。
Pods can be used to host vertically integrated application stacks (e.g. LAMP), but their primary motivation is to support co-located, co-managed helper programs, such as:
Individual pods are not intended to run multiple instances of the same application, in general.
For a longer explanation, see The Distributed System ToolKit: Patterns for Composite Containers.
Why not just run multiple programs in a single (Docker) container?
Why not support affinity-based co-scheduling of containers?
That approach would provide co-location, but would not provide most of the benefits of pods, such as resource sharing, IPC, guaranteed fate sharing, and simplified management.
Pods aren’t intended to be treated as durable entities. They won’t survive scheduling failures, node failures, or other evictions, such as due to lack of resources, or in the case of node maintenance.
In general, users shouldn’t need to create pods directly. They should almost always use controllers even for singletons, for example, Deployments). Controllers provide self-healing with a cluster scope, as well as replication and rollout management. Controllers like StatefulSet can also provide support to stateful pods.
The use of collective APIs as the primary user-facing primitive is relatively common among cluster scheduling systems, including Borg, Marathon, Aurora, and Tupperware.
Pod is exposed as a primitive in order to facilitate:
Because pods represent running processes on nodes in the cluster, it is important to allow those processes to gracefully terminate when they are no longer needed (vs being violently killed with a KILL signal and having no chance to clean up). Users should be able to request deletion and know when processes terminate, but also be able to ensure that deletes eventually complete. When a user requests deletion of a pod the system records the intended grace period before the pod is allowed to be forcefully killed, and a TERM signal is sent to the main process in each container. Once the grace period has expired the KILL signal is sent to those processes and the pod is then deleted from the API server. If the Kubelet or the container manager is restarted while waiting for processes to terminate, the termination will be retried with the full grace period.
优雅地关闭pod,首先发送TERM信号,超过等待时间后发送KILL信号。
An example flow:
preStop
hook is still running after the grace period expires, step 2 is then invoked with a small (2 second) extended grace period.By default, all deletes are graceful within 30 seconds. The kubectl delete
command supports the --grace-period=<seconds>
option which allows a user to override the default and specify their own value. The value 0
force deletes the pod. In kubectl version >= 1.5, you must specify an additional flag --force
along with --grace-period=0
in order to perform force deletions.
Force deletion of a pod is defined as deletion of a pod from the cluster state and etcd immediately. When a force deletion is performed, the apiserver does not wait for confirmation from the kubelet that the pod has been terminated on the node it was running on. It removes the pod in the API immediately so a new pod can be created with the same name. On the node, pods that are set to terminate immediately will still be given a small grace period before being force killed.
Force deletions can be potentially dangerous for some pods and should be performed with caution. In case of StatefulSet pods, please refer to the task documentation for deleting Pods from a StatefulSet.
From Kubernetes v1.1, any container in a pod can enable privileged mode, using the privileged
flag on the SecurityContext
of the container spec. This is useful for containers that want to use linux capabilities like manipulating the network stack and accessing devices. Processes within the container get almost the same privileges that are available to processes outside a container. With privileged mode, it should be easier to write network and volume plugins as separate pods that don’t need to be compiled into the kubelet.
能够操控网络堆栈、操做设备。容器中的进程几乎享有容器外进程的全部特权。单独的pod更容易地写入网络和卷
If the master is running Kubernetes v1.1 or higher, and the nodes are running a version lower than v1.1, then new privileged pods will be accepted by api-server, but will not be launched. They will be pending state. If user calls kubectl describe pod FooPodName
, user can see the reason why the pod is in pending state. The events table in the describe command output will say: Error validating pod "FooPodName"."FooPodNamespace" from api, ignoring: spec.containers[0].securityContext.privileged: forbidden '<*>(0xc2089d3248)true'
若是master的版本高,可是node的版本低,使用特权模式的pods会处于pending状态。
If the master is running a version lower than v1.1, then privileged pods cannot be created. If user attempts to create a pod, that has a privileged container, the user will get the following error: The Pod "FooPodName" is invalid. spec.containers[0].securityContext.privileged: forbidden '<*>(0xc20b222db0)true'
若是master的版本低,特权pods建立时会报错。
Pod is a top-level resource in the Kubernetes REST API. More details about the API object can be found at: Pod API object.