kube-scheduler 源码调试

发布时间 2023-07-17 11:00:35作者: 偶尔发呆

1. 创建一个 nginx Deployment,nginx-pod.yml 文件内容如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

2. 执行命令 

cluster/kubectl.sh apply -f nginx-pod.yml

3. 在 pkg/scheduler/schedule_one.go:66 断点,调用栈如下

 4. 略去 scheduler 的 filter 和 score 环节,我们重点看 bind 方法,把 pod 和 node 绑定起来

 5. scheduler 为 pod 选取合适的 node 后,进行绑定,这个绑定操作到底做了什么呢?继续跟代码

 我们看到,bind 操作其实是向 apiserver 发送了一个 post 请求,大致看下 post 请求的 body,能猜出来是 pod 和 node 的信息

6. 那么 apiserver 是如何处理这个请求的呢 ?稍后写一篇笔记描述