一. 前言
Pod是Kubernetes中能够创建和部署的最小单元,是Kubernetes集群中的一个应用实例,总是部署在同一个节点Node上。Pod中包含了一个或多个容器,还包括了存储、网络等各个容器共享的资源。Pod支持多种容器环境,Docker则是最流行的容器环境。
二. 配置信息
Pod的配置信息中有几个重要部分,apiVersion、kind、metadata、spec以及status。
其中apiVersion和kind是比较固定的,status是运行时的状态,所以最重要的就是metadata和spec两个部分。
2.1. pod 样例
apiVersion: v1
kind: Pod
metadata:
name: pod-test-666
labels:
app: podtest
env: boyi
spec:
restartPolicy: Never
volumes:
- name: shared-data
hostPath:
path: /opt/k8s/shared-data
containers:
- name: shell-job
image: centos:7
volumeMounts:
- name: shared-data
mountPath: /pod-data
command: ["/bin/sh"]
args: ["-c", "cd /pod-data/ && /pod-data/entrypoint.sh"]
2.2. 概念
pod中核心分为五部分 : apiVersion、kind、metadata、spec以及status。
序号 | 属性名称 | 属性类型 | 是否必选 | 备注 |
---|---|---|---|---|
1 | apiVersion | String | 是 | 版本号 : v1 |
2 | kind | String | 是 | Pod |
3 | metadata | Object | 是 | 元数据信息 |
4 | spec | Object | 是 | Pod中容器的详细信息 |
5 | status | – | – | 任务的执行状态,不在pod中定义 |
2.3. metadata 常用属性
序号 | 属性名称 | 属性类型 | 是否必选 | 备注 |
---|---|---|---|---|
1 | metadata.name | String | 是 | Pod 名称 |
2 | metadata.namespce | String | 是 | Pod所属namespace |
3 | metadata.labels[] | List | 否 | 自定义标签列表 |
4 | metadata.annotation[] | List | 否 | 自定义注解列表 |
2.4. spec
序号 | 属性名称 | 属性类型 | 是否必选 | 备注 |
---|---|---|---|---|
1 | spec.containers[] | List | 是 | Pod中的容器列表 |
2 | spec.containers[].name | String | 是 | 容器的名称 |
3 | spec.containers[].image | String | 是 | 容器镜像名称 |
4 | spec.containers[].imagePullPolicy | String | - - | 镜像拉取策略: 可选值: Always,Never,IfNotPresent,默认值Always Always:每次都尝试重新拉取镜像 IfNotPresent: 如果本地有镜像使用本地,否则拉取远程镜像 Never: 表示仅使用本地镜像 |
5 | spec.containers[].command[] | List | - - | 容器启动命令列表,如果不指定,则使用镜像打包时使用的启动命令 |
6 | spec.containers[].args[] | List | - - | 容器启动命令参数列表 |
7 | spec.containers[].workingDir | String | - - | 容器的工作目录 |
8 | spec.containers[].volumeMounts[] | List | - - | 挂载到容器内部的存储卷配置 |
9 | spec.containers[]…volumeMounts[].name | String | - - | 引用Pod定义的共享存储卷的名称,需要使用volumes[]部分定义的共享存储卷名称 |
10 | spec.containers[]…volumeMounts[].mountPath | String | - - | 存储卷在容器内挂载的绝对路径,应少于512个字符 |
11 | spec.containers[]…volumeMounts[].readOnly | Boolean | - - | 是否为只读模式,默认读写模式 |
12 | spec.containers[].ports[] | List | - - | 容器需要暴露的端口号列表 |
13 | spec.containers[].ports[].name | String | - - | 端口的名称 |
14 | spec.containers[].ports[].containerPort | Int | - - | 容器需要监听的端口号 |
15 | spec.containers[].ports[].hostPort | Int | - - | 容器所在主机需要监听的端口号,默认与containerPort相同. 设置hostPort时,同一台宿主机将无法启动该容器的第二份副本. |
16 | spec.containers[].ports[].protocol | String | - - | 端口协议,支持TCP和UDP,默认TCP |
17 | spec.containers[].env[] | List | - - | 容器运行前需要设置的环境变量列表 |
18 | spec.containers[].env[].name | String | - - | 环境变量的名称 |
19 | spec.containers[].env[].value | String | - - | 环境变量的值 |
20 | spec.containers[].resources | Object | - - | 资源限制和资源请求设置 |
21 | spec.containers[].resources.limits | Object | - - | 资源限制设置 |
22 | spec.containers[].resources.limits.cpu | String | - - | cpu限制 |
23 | spec.containers[].resources.limits.memory | String | - - | 内存限制 |
24 | spec.containers[].resources.requests | Object | - - | 资源限制设置 |
25 | spec.containers[].resources.requests.cpu | String | - - | 容器初始化,cpu请求数量 |
26 | spec.containers[].resources.requests.memory | String | - - | 容器初始化,内存请求数量 |
27 | spec.volumes[] | List | - - | 在该Pod上定义的共享存储列表 |
28 | spec.volumes[].name | String | - - | 共享存储卷的名称,在一个Pod中每个存储卷定义一个名称, 容器定义部分的spec.containers[]..volumeMounts[].name 将引用该共享存储卷的名称. |
29 | spec.volumes[].emptyDir | Object | - - | 类型为emptyDir的存储卷,表示与Pod同生命周期的一个临时目录,其值为一个空对象: emptyDir:{} |
30 | spec.volumes[].hostPath | Object | - - | 类型为hostPath的存储卷,表示Pod容器挂载的宿主机目录,通过volumes[].hostPath.path指定 |
31 | spec.volumes[].hostPath.path | String | - - | Pod容器挂载的宿主机目录 |
32 | spec.volumes[].secret | Object | - - | 类型为secret的存储卷,表示挂载集群预定义的secret对象到容器内部 |
33 | spec.volumes[].configMap | Object | - - | 类型为configMap的存储卷,表示挂载集群预定义的configMap对象到容器内部 |
34 | spec.volumes[].livenessProbe | Object | - - | 对Pod内各容器健康检查的设置,当探测无响应几次之后,系统将自动重启该容器. 可以设置的方法包括: exec,httpGet和tcpSocket. 对一个容器仅需设置一种健康检查方法. |
35 | spec.volumes[].livenessProbe.exec | Object | - - | 对Pod内各容器健康检查的设置, exec方式 |
36 | spec.volumes[].livenessProbe.exec.command[] | String | - - | exec方式需要指定的命令或者脚本 |
37 | spec.volumes[].livenessProbe.httpGet | Object | - - | 对Pod内各容器健康检查的设置,httpGet方式. 需要指定path,port. |
38 | spec.volumes[].livenessProbe.tcpSocket | Object | - - | 对Pod内各容器健康检查,tcpSocket方式. |
39 | spec.volumes[].livenessProbe.initialDelaySeconds | Number | - - | 容器启动完成后首次探测的时间,单位s |
40 | spec.volumes[].livenessProbe.timeoutSeconds | Number | - - | 对容器健康检查的探测等待响应的超时时间设置,单位s. 默认值1s. |
41 | spec.volumes[].livenessProbe.periodSeconds | Number | - - | 对容器健康检查的定期探测时间设置,单位s, 默认10s探测一次 |
42 | spec.restartPolicy | String | - - | Pod的重启策略,可选值为Always,OnFailure. 默认值为Always 1. Always: Pod一旦终止运行,无论容器是如何终止的,容器都将重启. 2.OnFailure: 只有Pod以非零退出码终止时,才重启该容器. 如果容器正常结束,则不容器. |
43 | spec.nodeSelector | Object | - - | 设置Node的label, 以key:value格式指定,Pod将会被调度到具有这些Label的Node上. |
44 | spec.imagePullSecrets | Object | - - | pull镜像时使用的secret名称,以name:secretkey格式指定 |
45 | spec.hostNetwork | Boolean | - - | 是否使用主机网络模式,默认值是false. 设置为true表示容器使用宿主机网络,不再使用Docker网桥,该Pod将无法在同一台宿主机上启动第2个副本. |
2.5. status
像单独的容器应用一样,Pod并不是持久运行的。Pod创建后,Kubernetes为其分配一个UID,并且通过Controller调度到Node中运行,然后Pod一直保持运行状态直到运行正常结束或者被删除。在Node发生故障时,Controller负责将其调度到其他的Node中。Kubernetes为Pod定义了几种状态,分别如下:
三. 常用的操作指令
3.1. 创建
使用配置文件的方式创建Pod。
$ kubectl create -f first-pod.yml
3.2. 查看配置
kubectl get pod first-pod -o yaml
或者
kubectl describe pod az-sleep -o yaml
3.3. 查看日志
kubectl logs first-pod
如果Pod中有多个容器,查看特定容器的日志需要指定容器名称
kubectl logs pod-name -c container-name
3.4. 标签管理
- 显示Pod的标签
[root@master01 ~]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
first-pod 1/1 Running 0 15m app=bash
- 使用 second-pod.yml 我们再创建一个包含两个标签的Pod。
[root@master01 ~]# kubectl create -f first-pod.yml
pod/second-pod created
[root@master01 ~]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
first-pod 1/1 Running 0 17m app=bash
second-pod 0/1 ContainerCreating 0 20s app=bash,tir=backend
- 根据标签来查询Pod。
[root@master01 ~]# kubectl get pods -l tir=backend --show-labels
NAME READY STATUS RESTARTS AGE LABELS
second-pod 1/1 Running 0 1m app=bash,tir=backend
- 增加标签
[root@master01 ~]# kubectl label pod first-pod tir=frontend
pod/first-pod labeled
[root@master01 ~]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
first-pod 1/1 Running 0 24m app=bash,tir=frontend
second-pod 1/1 Running 0 7m app=bash,tir=backend
- 修改标签
[root@master01 ~]# kubectl label pod first-pod tir=unkonwn --overwrite
pod/first-pod labeled
[root@master01 ~]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
first-pod 1/1 Running 0 25m app=bash,tir=unkonwn
second-pod 1/1 Running 0 8m app=bash,tir=backend
- 可以将标签显示为列
[root@master01 ~]# kubectl get pods -L app,tir
NAME READY STATUS RESTARTS AGE APP TIR
first-pod 1/1 Running 0 26m bash unkonwn
second-pod 1/1 Running 0 9m bash backend
3.5. 删除pod
[root@master01 ~]# kubectl delete pods first-pod
pod "first-pod" deleted
也可以根据标签选择器删除。
[root@master01 ~]# kubectl delete pods -l tir=backend
pod "second-pod" deleted
四. 通过指令查看pod帮助信息
[root@master01 ~]# kubectl explain pod
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
kind <string>
Kind is a string value representing the REST resource this object
represents. Servers may infer this from the endpoint the client submits
requests to. Cannot be updated. In CamelCase. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
metadata <Object>
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
spec <Object>
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
status <Object>
Most recently observed status of the pod. This data may not be up to date.
Populated by the system. Read-only. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
- 查看 pod 中的kind 描述
[root@master01 ~]# kubectl explain pod.kind
KIND: Pod
VERSION: v1
FIELD: kind <string>
DESCRIPTION:
Kind is a string value representing the REST resource this object
represents. Servers may infer this from the endpoint the client submits
requests to. Cannot be updated. In CamelCase. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
- 查看 pod 中的apiVersion 描述
[root@master01 ~]# kubectl explain pod.apiVersion
KIND: Pod
VERSION: v1
FIELD: apiVersion <string>
DESCRIPTION:
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
- 查看 pod 中的metadata 描述
[root@master01 ~]# kubectl explain pod.metadata
KIND: Pod
VERSION: v1
RESOURCE: metadata <Object>
DESCRIPTION:
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
ObjectMeta is metadata that all persisted resources must have, which
includes all objects users must create.
FIELDS:
annotations <map[string]string>
Annotations is an unstructured key value map stored with a resource that
may be set by external tools to store and retrieve arbitrary metadata. They
are not queryable and should be preserved when modifying objects. More
info: http://kubernetes.io/docs/user-guide/annotations
clusterName <string>
The name of the cluster which the object belongs to. This is used to
distinguish resources with same name and namespace in different clusters.
This field is not set anywhere right now and apiserver is going to ignore
it if set in create or update request.
creationTimestamp <string>
CreationTimestamp is a timestamp representing the server time when this
object was created. It is not guaranteed to be set in happens-before order
across separate operations. Clients may not set this value. It is
represented in RFC3339 form and is in UTC.
Populated by the system. Read-only. Null for lists. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
deletionGracePeriodSeconds <integer>
Number of seconds allowed for this object to gracefully terminate before it
will be removed from the system. Only set when deletionTimestamp is also
set. May only be shortened. Read-only.
deletionTimestamp <string>
DeletionTimestamp is RFC 3339 date and time at which this resource will be
deleted. This field is set by the server when a graceful deletion is
requested by the user, and is not directly settable by a client. The
resource is expected to be deleted (no longer visible from resource lists,
and not reachable by name) after the time in this field, once the
finalizers list is empty. As long as the finalizers list contains items,
deletion is blocked. Once the deletionTimestamp is set, this value may not
be unset or be set further into the future, although it may be shortened or
the resource may be deleted prior to this time. For example, a user may
request that a pod is deleted in 30 seconds. The Kubelet will react by
sending a graceful termination signal to the containers in the pod. After
that 30 seconds, the Kubelet will send a hard termination signal (SIGKILL)
to the container and after cleanup, remove the pod from the API. In the
presence of network partitions, this object may still exist after this
timestamp, until an administrator or automated process can determine the
resource is fully terminated. If not set, graceful deletion of the object
has not been requested.
Populated by the system when a graceful deletion is requested. Read-only.
More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
finalizers <[]string>
Must be empty before the object is deleted from the registry. Each entry is
an identifier for the responsible component that will remove the entry from
the list. If the deletionTimestamp of the object is non-nil, entries in
this list can only be removed. Finalizers may be processed and removed in
any order. Order is NOT enforced because it introduces significant risk of
stuck finalizers. finalizers is a shared field, any actor with permission
can reorder it. If the finalizer list is processed in order, then this can
lead to a situation in which the component responsible for the first
finalizer in the list is waiting for a signal (field value, external
system, or other) produced by a component responsible for a finalizer later
in the list, resulting in a deadlock. Without enforced ordering finalizers
are free to order amongst themselves and are not vulnerable to ordering
changes in the list.
generateName <string>
GenerateName is an optional prefix, used by the server, to generate a
unique name ONLY IF the Name field has not been provided. If this field is
used, the name returned to the client will be different than the name
passed. This value will also be combined with a unique suffix. The provided
value has the same validation rules as the Name field, and may be truncated
by the length of the suffix required to make the value unique on the
server.
If this field is specified and the generated name exists, the server will
NOT return a 409 - instead, it will either return 201 Created or 500 with
Reason ServerTimeout indicating a unique name could not be found in the
time allotted, and the client should retry (optionally after the time
indicated in the Retry-After header).
Applied only if Name is not specified. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency
generation <integer>
A sequence number representing a specific generation of the desired state.
Populated by the system. Read-only.
labels <map[string]string>
Map of string keys and values that can be used to organize and categorize
(scope and select) objects. May match selectors of replication controllers
and services. More info: http://kubernetes.io/docs/user-guide/labels
managedFields <[]Object>
ManagedFields maps workflow-id and version to the set of fields that are
managed by that workflow. This is mostly for internal housekeeping, and
users typically shouldn't need to set or understand this field. A workflow
can be the user's name, a controller's name, or the name of a specific
apply path like "ci-cd". The set of fields is always in the version that
the workflow used when modifying the object.
name <string>
Name must be unique within a namespace. Is required when creating
resources, although some resources may allow a client to request the
generation of an appropriate name automatically. Name is primarily intended
for creation idempotence and configuration definition. Cannot be updated.
More info: http://kubernetes.io/docs/user-guide/identifiers#names
namespace <string>
Namespace defines the space within which each name must be unique. An empty
namespace is equivalent to the "default" namespace, but "default" is the
canonical representation. Not all objects are required to be scoped to a
namespace - the value of this field for those objects will be empty.
Must be a DNS_LABEL. Cannot be updated. More info:
http://kubernetes.io/docs/user-guide/namespaces
ownerReferences <[]Object>
List of objects depended by this object. If ALL objects in the list have
been deleted, this object will be garbage collected. If this object is
managed by a controller, then an entry in this list will point to this
controller, with the controller field set to true. There cannot be more
than one managing controller.
resourceVersion <string>
An opaque value that represents the internal version of this object that
can be used by clients to determine when objects have changed. May be used
for optimistic concurrency, change detection, and the watch operation on a
resource or set of resources. Clients must treat these values as opaque and
passed unmodified back to the server. They may only be valid for a
particular resource or set of resources.
Populated by the system. Read-only. Value must be treated as opaque by
clients and . More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
selfLink <string>
SelfLink is a URL representing this object. Populated by the system.
Read-only.
DEPRECATED Kubernetes will stop propagating this field in 1.20 release and
the field is planned to be removed in 1.21 release.
uid <string>
UID is the unique in time and space value for this object. It is typically
generated by the server on successful creation of a resource and is not
allowed to change on PUT operations.
Populated by the system. Read-only. More info:
http://kubernetes.io/docs/user-guide/identifiers#uids
- 查看 pod 中的spec 描述
[root@master01 ~]# kubectl explain pod.spec
KIND: Pod
VERSION: v1
RESOURCE: spec <Object>
DESCRIPTION:
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
PodSpec is a description of a pod.
FIELDS:
activeDeadlineSeconds <integer>
Optional duration in seconds the pod may be active on the node relative to
StartTime before the system will actively try to mark it failed and kill
associated containers. Value must be a positive integer.
affinity <Object>
If specified, the pod's scheduling constraints
automountServiceAccountToken <boolean>
AutomountServiceAccountToken indicates whether a service account token
should be automatically mounted.
containers <[]Object> -required-
List of containers belonging to the pod. Containers cannot currently be
added or removed. There must be at least one container in a Pod. Cannot be
updated.
dnsConfig <Object>
Specifies the DNS parameters of a pod. Parameters specified here will be
merged to the generated DNS configuration based on DNSPolicy.
dnsPolicy <string>
Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values are
'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS
parameters given in DNSConfig will be merged with the policy selected with
DNSPolicy. To have DNS options set along with hostNetwork, you have to
specify DNS policy explicitly to 'ClusterFirstWithHostNet'.
enableServiceLinks <boolean>
EnableServiceLinks indicates whether information about services should be
injected into pod's environment variables, matching the syntax of Docker
links. Optional: Defaults to true.
ephemeralContainers <[]Object>
List of ephemeral containers run in this pod. Ephemeral containers may be
run in an existing pod to perform user-initiated actions such as debugging.
This list cannot be specified when creating a pod, and it cannot be
modified by updating the pod spec. In order to add an ephemeral container
to an existing pod, use the pod's ephemeralcontainers subresource. This
field is alpha-level and is only honored by servers that enable the
EphemeralContainers feature.
hostAliases <[]Object>
HostAliases is an optional list of hosts and IPs that will be injected into
the pod's hosts file if specified. This is only valid for non-hostNetwork
pods.
hostIPC <boolean>
Use the host's ipc namespace. Optional: Default to false.
hostNetwork <boolean>
Host networking requested for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
Default to false.
hostPID <boolean>
Use the host's pid namespace. Optional: Default to false.
hostname <string>
Specifies the hostname of the Pod If not specified, the pod's hostname will
be set to a system-defined value.
imagePullSecrets <[]Object>
ImagePullSecrets is an optional list of references to secrets in the same
namespace to use for pulling any of the images used by this PodSpec. If
specified, these secrets will be passed to individual puller
implementations for them to use. For example, in the case of docker, only
DockerConfig type secrets are honored. More info:
https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
initContainers <[]Object>
List of initialization containers belonging to the pod. Init containers are
executed in order prior to containers being started. If any init container
fails, the pod is considered to have failed and is handled according to its
restartPolicy. The name for an init container or normal container must be
unique among all containers. Init containers may not have Lifecycle
actions, Readiness probes, Liveness probes, or Startup probes. The
resourceRequirements of an init container are taken into account during
scheduling by finding the highest request/limit for each resource type, and
then using the max of of that value or the sum of the normal containers.
Limits are applied to init containers in a similar fashion. Init containers
cannot currently be added or removed. Cannot be updated. More info:
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
nodeName <string>
NodeName is a request to schedule this pod onto a specific node. If it is
non-empty, the scheduler simply schedules this pod onto that node, assuming
that it fits resource requirements.
nodeSelector <map[string]string>
NodeSelector is a selector which must be true for the pod to fit on a node.
Selector which must match a node's labels for the pod to be scheduled on
that node. More info:
https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
overhead <map[string]string>
Overhead represents the resource overhead associated with running a pod for
a given RuntimeClass. This field will be autopopulated at admission time by
the RuntimeClass admission controller. If the RuntimeClass admission
controller is enabled, overhead must not be set in Pod create requests. The
RuntimeClass admission controller will reject Pod create requests which
have the overhead already set. If RuntimeClass is configured and selected
in the PodSpec, Overhead will be set to the value defined in the
corresponding RuntimeClass, otherwise it will remain unset and treated as
zero. More info:
https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
This field is beta-level as of Kubernetes v1.18, and is only honored by
servers that enable the PodOverhead feature.
preemptionPolicy <string>
PreemptionPolicy is the Policy for preempting pods with lower priority. One
of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.
This field is beta-level, gated by the NonPreemptingPriority feature-gate.
priority <integer>
The priority value. Various system components use this field to find the
priority of the pod. When Priority Admission Controller is enabled, it
prevents users from setting this field. The admission controller populates
this field from PriorityClassName. The higher the value, the higher the
priority.
priorityClassName <string>
If specified, indicates the pod's priority. "system-node-critical" and
"system-cluster-critical" are two special keywords which indicate the
highest priorities with the former being the highest priority. Any other
name must be defined by creating a PriorityClass object with that name. If
not specified, the pod priority will be default or zero if there is no
default.
readinessGates <[]Object>
If specified, all readiness gates will be evaluated for pod readiness. A
pod is ready when all its containers are ready AND all conditions specified
in the readiness gates have status equal to "True" More info:
https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates
restartPolicy <string>
Restart policy for all containers within the pod. One of Always, OnFailure,
Never. Default to Always. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
runtimeClassName <string>
RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group,
which should be used to run this pod. If no RuntimeClass resource matches
the named class, the pod will not be run. If unset or empty, the "legacy"
RuntimeClass will be used, which is an implicit class with an empty
definition that uses the default runtime handler. More info:
https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class This is a
beta feature as of Kubernetes v1.14.
schedulerName <string>
If specified, the pod will be dispatched by specified scheduler. If not
specified, the pod will be dispatched by default scheduler.
securityContext <Object>
SecurityContext holds pod-level security attributes and common container
settings. Optional: Defaults to empty. See type description for default
values of each field.
serviceAccount <string>
DeprecatedServiceAccount is a depreciated alias for ServiceAccountName.
Deprecated: Use serviceAccountName instead.
serviceAccountName <string>
ServiceAccountName is the name of the ServiceAccount to use to run this
pod. More info:
https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
setHostnameAsFQDN <boolean>
If true the pod's hostname will be configured as the pod's FQDN, rather
than the leaf name (the default). In Linux containers, this means setting
the FQDN in the hostname field of the kernel (the nodename field of struct
utsname). In Windows containers, this means setting the registry value of
hostname for the registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters to
FQDN. If a pod does not have FQDN, this has no effect. Default to false.
shareProcessNamespace <boolean>
Share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from
other containers in the same pod, and the first process in each container
will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both
be set. Optional: Default to false.
subdomain <string>
If specified, the fully qualified Pod hostname will be
"<hostname>.<subdomain>.<pod namespace>.svc.<cluster domain>". If not
specified, the pod will not have a domainname at all.
terminationGracePeriodSeconds <integer>
Optional duration in seconds the pod needs to terminate gracefully. May be
decreased in delete request. Value must be non-negative integer. The value
zero indicates stop immediately via the kill signal (no opportunity to shut
down). If this value is nil, the default grace period will be used instead.
The grace period is the duration in seconds after the processes running in
the pod are sent a termination signal and the time when the processes are
forcibly halted with a kill signal. Set this value longer than the expected
cleanup time for your process. Defaults to 30 seconds.
tolerations <[]Object>
If specified, the pod's tolerations.
topologySpreadConstraints <[]Object>
TopologySpreadConstraints describes how a group of pods ought to spread
across topology domains. Scheduler will schedule pods in a way which abides
by the constraints. All topologySpreadConstraints are ANDed.
volumes <[]Object>
List of volumes that can be mounted by containers belonging to the pod.
More info: https://kubernetes.io/docs/concepts/storage/volumes
- 查看 pod 中的status 描述
[root@master01 ~]# kubectl explain pod.status
KIND: Pod
VERSION: v1
RESOURCE: status <Object>
DESCRIPTION:
Most recently observed status of the pod. This data may not be up to date.
Populated by the system. Read-only. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
PodStatus represents information about the status of a pod. Status may
trail the actual state of a system, especially if the node that hosts the
pod cannot contact the control plane.
FIELDS:
conditions <[]Object>
Current service state of pod. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-conditions
containerStatuses <[]Object>
The list has one entry per container in the manifest. Each entry is
currently the output of `docker inspect`. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status
ephemeralContainerStatuses <[]Object>
Status for any ephemeral containers that have run in this pod. This field
is alpha-level and is only populated by servers that enable the
EphemeralContainers feature.
hostIP <string>
IP address of the host to which the pod is assigned. Empty if not yet
scheduled.
initContainerStatuses <[]Object>
The list has one entry per init container in the manifest. The most recent
successful init container will have ready = true, the most recently started
container will have startTime set. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status
message <string>
A human readable message indicating details about why the pod is in this
condition.
nominatedNodeName <string>
nominatedNodeName is set only when this pod preempts other pods on the
node, but it cannot be scheduled right away as preemption victims receive
their graceful termination periods. This field does not guarantee that the
pod will be scheduled on this node. Scheduler may decide to place the pod
elsewhere if other nodes become available sooner. Scheduler may also decide
to give the resources on this node to a higher priority pod that is created
after preemption. As a result, this field may be different than
PodSpec.nodeName when the pod is scheduled.
phase <string>
The phase of a Pod is a simple, high-level summary of where the Pod is in
its lifecycle. The conditions array, the reason and message fields, and the
individual container status arrays contain more detail about the pod's
status. There are five possible phase values:
Pending: The pod has been accepted by the Kubernetes system, but one or
more of the container images has not been created. This includes time
before being scheduled as well as time spent downloading images over the
network, which could take a while. Running: The pod has been bound to a
node, and all of the containers have been created. At least one container
is still running, or is in the process of starting or restarting.
Succeeded: All containers in the pod have terminated in success, and will
not be restarted. Failed: All containers in the pod have terminated, and at
least one container has terminated in failure. The container either exited
with non-zero status or was terminated by the system. Unknown: For some
reason the state of the pod could not be obtained, typically due to an
error in communicating with the host of the pod.
More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-phase
podIP <string>
IP address allocated to the pod. Routable at least within the cluster.
Empty if not yet allocated.
podIPs <[]Object>
podIPs holds the IP addresses allocated to the pod. If this field is
specified, the 0th entry must match the podIP field. Pods may be allocated
at most 1 value for each of IPv4 and IPv6. This list is empty if no IPs
have been allocated yet.
qosClass <string>
The Quality of Service (QOS) classification assigned to the pod based on
resource requirements See PodQOSClass type for available QOS classes More
info:
https://git.k8s.io/community/contributors/design-proposals/node/resource-qos.md
reason <string>
A brief CamelCase message indicating details about why the pod is in this
state. e.g. 'Evicted'
startTime <string>
RFC 3339 date and time at which the object was acknowledged by the Kubelet.
This is before the Kubelet pulled the container image(s) for the pod.
引用:
https://kubernetes.io/zh/docs/concepts/workloads/pods/
https://www.cnblogs.com/cocowool/p/kubernetes_pod_detail.html