过程:
1、用户创建pod的信息通过API Server存储到etcd中,etcd记录pod的元信息并将结果返回API Server
2、API Server告知调度器请求资源调度分配,调度器通过计算,将优先级高的node与pod绑定并告知API Server
3、API Server将此信息写入etcd,得到etcd回复后调用kubelet创建pod
4、kubelet使用docker run创建pod内的容器,得到反馈信息后将容器信息告知API Server
5、API Server将收到的信息写入etcd并得到回馈
6、此时使用kubectl get pod就可以查看到信息了
1、nodeName:
2、nodeSelector:
两种方式都是通过yaml文件来实现
[root@master test]# vim nodename.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-example
labels:
app: nginx
spec:
nodeName: 20.0.0.54
containers:
- name: nginx
image: nginx:1.15
[root@master test]# kubectl apply -f nodename.yaml
pod/pod-example created
[root@master test]# kubectl get pod -w
NAME READY STATUS RESTARTS AGE
pod-example 0/1 ContainerCreating 0 7s
pod-example 1/1 Running 0 21s
[root@master test]# kubectl describe pod pod-example
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Events: '发现没有经过调度器,node节点也是指定的'
Normal Pulling 4m29s kubelet, 20.0.0.54 pulling image "nginx:1.15"
Normal Pulled 4m11s kubelet, 20.0.0.54 Successfully pulled image "nginx:1.15"
Normal Created 4m11s kubelet, 20.0.0.54 Created container
Normal Started 4m11s kubelet, 20.0.0.54 Started container
[root@master test]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
pod-example 1/1 Running 0 12m 172.17.83.2 20.0.0.54 <none>
[root@master test]# kubectl label --help
Usage:
kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ...
KEY_N=VAL_N [--resource-version=version] [options]
[root@master test]# kubectl get node
NAME STATUS ROLES AGE VERSION
20.0.0.54 Ready <none> 6d v1.12.3
20.0.0.56 Ready <none> 5d23h v1.12.3
[root@master test]# kubectl label node 20.0.0.54 node=node1
node/20.0.0.54 labeled
[root@master test]# kubectl label node 20.0.0.56 node=node2
node/20.0.0.56 labeled
[root@master test]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
20.0.0.54 Ready <none> 5d9h v1.12.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=20.0.0.54,node=node1
20.0.0.56 Ready <none> 5d9h v1.12.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=20.0.0.56,node=node2
[root@master test]# vim nodeselector.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-example
labels:
app: nginx
spec:
nodeSelector:
node: node1
containers:
- name: nginx
image: nginx:1.15
[root@master test]# kubectl create -f nodeselector-test.yaml
pod/pod-example created
[root@master test]# kubectl get pod -w
NAME READY STATUS RESTARTS AGE
pod-example 0/1 ContainerCreating 0 13s
pod-example 1/1 Running 0 30s
[root@master test]# kubectl describe pod pod-example
Events: '通过事件可以观察经过调度器分配,分配的节点ip也是对的'
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m3s default-scheduler Successfully assigned default/pod-example to 20.0.0.54
Normal Pulling 2m2s kubelet, 20.0.0.54 pulling image "nginx:1.15"
Normal Pulled 93s kubelet, 20.0.0.54 Successfully pulled image "nginx:1.15"
Normal Created 93s kubelet, 20.0.0.54 Created container
Normal Started 93s kubelet, 20.0.0.54 Started container
状态值 | 描述 |
---|---|
pending | pod创建已经提交到kubernetes。但是,因为某种原因而不能顺利创建。例如下载镜像慢,调度不成功 |
running | pod已经绑定到一个节点,并且已经创建了所有容器。至少有一个容器正在运行中,或正在启动或重新启动 |
succeeded | pod中的所有容器都已成功终止,不会重新启动 |
failed | pod的所有容器均已终止,且至少有一个容器已在故障中终止。也就是说,容器要么以非零状态退出,要么被系统终止 |
unknown | 由于某种原因apiserver无法获得pod的状态,通常是由于mater与pod所在主机kubelet通信时出错 |
kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME)
[options]
kubectl logs pod_name
kubectl ecex -it pod_name bash