K8S手动调度Pod

手动调度Pod(不经过调度器)

适用场景

  • 调度器不工作时,临时救急
  • 封装实现自定义调度器

小故事

  • 过去几个版本的Daemonset都是由controller直接指定pod的运行节点,不经过调度器。
  • 直到1.11版本,DaemonSet的pod由scheduler调度才作为alpha特性引入

136服务器
/root/demo/manual_schedule.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: pod-manual-schedule
  name: pod-manual-schedule
  namespace: default
spec:
  nodeName: "192.168.174.135"
  containers:
  - name: my-pod
    image: nginx

说明
在创建pod时直接指定node节点,如上nodeName: "192.168.174.135"
执行手动调度pod命令
kubectl create -f manual_schedule.yaml

root@server02:~/demo# kubectl create -f manual_schedule.yaml
pod "pod-manual-schedule" created

在135节点创建

root@server01:~# kubectl get pod
NAME                  READY     STATUS              RESTARTS   AGE
pod-manual-schedule   0/1       ContainerCreating   0          8s
root@server01:~# kubectl get pod
NAME                  READY     STATUS    RESTARTS   AGE
pod-manual-schedule   1/1       Running   0          10s

kubectl describe pod pod-manual-schedule查看event过程

Events:
Type Reason Age From Message


Normal Pulling 9m kubelet, 192.168.174.135 pulling image “nginx”
Normal Pulled 9m kubelet, 192.168.174.135 Successfully pulled image “nginx”
Normal Created 9m kubelet, 192.168.174.135 Created container
Normal Started 9m kubelet, 192.168.174.135 Started container

修改yaml文件

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: pod-schedule
  name: pod-schedule
  namespace: default
spec:
  containers:
  - name: my-pod
    image: nginx

将nodeName去掉,然后重新创建pod,则自动调度到了137这个节点,而且,kubectl describe pod pod-schedule 查看这个pod的events创建过程中,可以看到是用默认的default-scheduler调度的
Events:
Type Reason Age From Message


Normal Scheduled 58s default-scheduler Successfully assigned pod-schedule to 192.168.174.137
Normal Pulling 57s kubelet, 192.168.174.137 pulling image “nginx”
Normal Pulled 49s kubelet, 192.168.174.137 Successfully pulled image “nginx”
Normal Created 49s kubelet, 192.168.174.137 Created container
Normal Started 49s kubelet, 192.168.174.137 Started container

学习华为kubernetes管理员实训课并感谢

你可能感兴趣的:(Kubernetes)