[root@k8s-master ~]# kubectl create -f pod-busybox.yaml pod/myapp-pod created [root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myapp-pod 0/1 ContainerCreating 0 11s # 正在创建pod
[root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myapp-pod 1/1 Running 0 21s # 状态为Running [root@k8s-master ~]#
[root@k8s-master ~]# kubectl explain pods.spec.containers KIND: Pod VERSION: v1
RESOURCE: containers <[]Object>
DESCRIPTION: 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.
A single application container that you want to run within a pod.
FIELDS: args <[]string> Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
command <[]string> Entrypoint array. Not executed within a shell. The docker image's ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
env <[]Object> List of environment variables to setin the container. Cannot be updated.
envFrom <[]Object> List of sources to populate environment variables in the container. The keys defined within a source must be a C_IDENTIFIER. All invalid keys will be reported as an event when the container is starting. When a key exists in multiple sources, the value associated with the last source will take precedence. Values defined by an Env with a duplicate key will take precedence. Cannot be updated.
image <string> Docker image name. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets. ......
基本操作
查询所有正在运行的pod
1 2 3
[root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myapp-pod 1/1 Running 0 21s
查询单个pod名,可以使用-w持续监听
1 2 3 4 5 6 7
[root@k8s-master ~]# kubectl get pod myapp-pod NAME READY STATUS RESTARTS AGE myapp-pod 1/1 Running 0 21m
[root@k8s-master ~]# kubectl get pod -w NAME READY STATUS RESTARTS AGE myapp-pod 1/1 Running 0 24m
查询详情,可以查看调度到哪台主机上
kubectl get pod {pod 名} -o wide
1 2 3 4
[root@k8s-master ~]# kubectl get pod myapp-pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES myapp-pod 1/1 Running 0 21m 10.244.2.6 k8s-node2 <none> <none> [root@k8s-master ~]#