[root@devops-101 ~]# 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/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/api-conventions.md#types-kinds
metadata <Object> Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata spec <Object> Specification of the desired behavior of the pod. More info: https://git.k8s.io/community/contributors/devel/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/api-conventions.md#spec-and-status [root@devops-101 ~]# 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/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.
[root@devops-101 ~]# kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS first-pod 1/1 Running 0 15m app=bash
使用 second-pod.yml 我们再创建一个包含两个标签的Pod。
1 2 3 4 5 6
[root@devops-101 ~]# kubectl create -f first-pod.yml pod/second-pod created [root@devops-101 ~]# 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。
1 2 3
[root@devops-101 ~]# 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
增加标签
1 2 3 4 5 6
[root@devops-101 ~]# kubectl label pod first-pod tir=frontend pod/first-pod labeled [root@devops-101 ~]# 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
修改标签
1 2 3 4 5 6
[root@devops-101 ~]# kubectl label pod first-pod tir=unkonwn --overwrite pod/first-pod labeled [root@devops-101 ~]# 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
可以将标签显示为列
1 2 3 4
[root@devops-101 ~]# 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
[root@devops-101 ~]# kubectl explain pod.spec.initContainers KIND: Pod VERSION: v1
RESOURCE: initContainers <[]Object>
DESCRIPTION: 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, or Liveness probes. The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limitfor 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/
A single application container that you want to run within a pod.
Kubernetes offers features to help run highly available applications at the same time as frequent voluntary disruptions. We call this set of features Disruption Budgets.