首页 > 代码库 > kubernetes Master部署之Scheduler 以及 HA部署(5)

kubernetes Master部署之Scheduler 以及 HA部署(5)

Kubernetes Scheduler作用是将Controller Manager将要新建的Pod按照特定的调度算法和调度策略绑定到集群中某个合适的Node上,并将绑定信息写入到etcd中。

一、部署Scheduler

下面生成kube-scheduler的kubeconfig文件,操作如下:

cd /etc/kubernetes
export KUBE_APISERVER="https://192.168.15.200:6443"

配置 cluster

kubectl config set-cluster kubernetes --certificate-authority=/etc/kubernetes/ssl/ca.pem --embed-certs=true --server=${KUBE_APISERVER} --kubeconfig=scheduler.conf

配置 credentials

kubectl config set-credentials system:kube-scheduler --client-certificate=/etc/kubernetes/ssl/scheduler.pem --embed-certs=true --client-key=/etc/kubernetes/ssl/scheduler-key.pem --kubeconfig=scheduler.conf

配置 context

kubectl config set-context system:kube-scheduler@kubernetes --cluster=kubernetes --user=system:kube-scheduler --kubeconfig=scheduler.conf

配置 default context

kubectl config use-context system:kube-scheduler@kubernetes --kubeconfig=scheduler.conf

将生成的scheduler.conf文件分发到各个 Master 节点的 /etc/kubernetes 目录下,如下:

scp scheduler.conf k8s-master02:/etc/kubernetes/                                      
scp scheduler.conf k8s-master03:/etc/kubernetes/

创建 kube-scheduler 的 systemd服务启动文件,如下:

export KUBE_APISERVER="https://192.168.15.200:6443"
cat > /usr/lib/systemd/system/kube-scheduler.service <<EOF
[Unit]
Description=kube-scheduler
After=network.target
After=kube-apiserver.service
 
[Service]
EnvironmentFile=-/etc/kubernetes/scheduler
ExecStart=/usr/local/bin/kube-scheduler         --logtostderr=true         --v=0         --master=${KUBE_APISERVER}         --kubeconfig=/etc/kubernetes/scheduler.conf         --leader-elect=true
Restart=on-failure
Type=simple
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target
EOF

 分发到其他主机:

scp /usr/lib/systemd/system/kube-scheduler.service k8s-master02:/usr/lib/systemd/system/                                          
scp /usr/lib/systemd/system/kube-scheduler.service k8s-master03:/usr/lib/systemd/system/

在各节点启动服务:

systemctl daemon-reload
systemctl enable kube-scheduler
systemctl start kube-scheduler
systemctl status kube-scheduler

三个 Master 节点上的 kube-schedule 部署完成,通过选举出一个 leader 工作。

查看 Kubernetes Master 集群各个核心组件的状态全部正常,如下所示:

[root@k8s-master01 kubernetes]# kubectl get cs
NAME                 STATUS    MESSAGE              ERROR
etcd-1               Healthy   {"health": "true"}   
scheduler            Healthy   ok                   
controller-manager   Healthy   ok                   
etcd-0               Healthy   {"health": "true"}   
etcd-2               Healthy   {"health": "true"}

 

kubernetes Master部署之Scheduler 以及 HA部署(5)