二进制部署k8s集群v1.23.9版本-8-安装scheduler组件
8.1、集群规划
主机名 | 角色 | IP |
---|---|---|
hfqg1-201 | kube-scheduler | 192.168.1.201 |
hfqg1-202 | kube-scheduler | 192.168.1.202 |
hfqg1-203 | kube-scheduler | 192.168.1.203 |
8.2、生成kube-scheduler证书
192.168.1.200服务器上操作
创建证书请求csr文件
/opt/certs/kube-scheduler-csr.json
[root@hfqg1-200 certs]# cat kube-scheduler-csr.json
{
"CN": "system:kube-scheduler",
"hosts": [
"127.0.0.1",
"192.168.1.196",
"192.168.1.197",
"192.168.1.198",
"192.168.1.199",
"192.168.1.200",
"192.168.1.201",
"192.168.1.202",
"192.168.1.203"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "beijing",
"L": "beijing",
"O": "system:masters",
"OU": "system"
}
]
}
生成证书
cd /opt/certs
cfssl gencert
-ca=ca.pem
-ca-key=ca-key.pem
-config=ca-config.json
-profile=kubernetes
kube-scheduler-csr.json | cfssl-json -bare kube-scheduler
ll kube-scheduler*.pem
8.3、拷贝证书
将证书拷贝到201、202、203服务器上
scp kube-scheduler.pem hfqg1-201:/opt/kubernetes/server/bin/certs/
scp kube-scheduler.pem hfqg1-202:/opt/kubernetes/server/bin/certs/
scp kube-scheduler*.pem hfqg1-203:/opt/kubernetes/server/bin/certs/
8.4、生成kubeconfig配置文件
192.168.1.201服务器上操作
/opt/kubernetes/server/bin/k8s-shell
[root@hfqg1-201 k8s-shell]# cat kube-scheduler-config.sh
#!/bin/bash
KUBE_CONFIG="/opt/kubernetes/server/bin/conf/kube-scheduler.kubeconfig"
KUBE_APISERVER="https://192.168.1.196:8443"
kubectl config set-cluster kubernetes
--certificate-authority=/opt/kubernetes/server/bin/certs/ca.pem
--embed-certs=true
--server=${KUBE_APISERVER}
--kubeconfig=${KUBE_CONFIG}
kubectl config set-credentials kube-scheduler
--client-certificate=/opt/kubernetes/server/bin/certs/kube-scheduler.pem
--client-key=/opt/kubernetes/server/bin/certs/kube-scheduler-key.pem
--embed-certs=true
--kubeconfig=${KUBE_CONFIG}
kubectl config set-context default
--cluster=kubernetes
--user=kube-scheduler
--kubeconfig=${KUBE_CONFIG}
kubectl config use-context default --kubeconfig=$
授权并执行脚本
chmod +x kube-scheduler-config.sh
./kube-scheduler-config.sh
8.5、把kubeconfig 文件拷贝到202和203主机
scp /opt/kubernetes/server/bin/conf/kube-scheduler.kubeconfig hfqg1-202:/opt/kubernetes/server/bin/conf/
scp /opt/kubernetes/server/bin/conf/kube-scheduler.kubeconfig hfqg1-203:/opt/kubernetes/server/bin/conf/
8.6、创建kube-scheduler启动脚本
cd /opt/kubernetes/server/bin/
[root@hfqg1-201 bin]# cat kube-scheduler.sh
#!/bin/bash
WORK_DIR=$(dirname $(readlink -f $0))
[ $? -eq 0 ] && cd $WORK_DIR || exit
/opt/kubernetes/server/bin/kube-scheduler
--address=127.0.0.1
--leader-elect=true
--kubeconfig=/opt/kubernetes/server/bin/conf/kube-scheduler.kubeconfig
--log-dir=/data/logs/kubernetes/kube-scheduler
--v=2
调整权限并创建日志目录
chmod +x kube-scheduler.sh
mkdir -p /data/logs/kubernetes/kube-scheduler
8.7、创建supervisor配置文件
[root@hfqg1-201 bin]# cat /etc/supervisord.d/kube-scheduler.ini
[program:kube-scheduler-1-201]
command=/opt/kubernetes/server/bin/kube-scheduler.sh
numprocs=1
directory=/opt/kubernetes/server/bin
autostart=true
autorestart=true
startsecs=30
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=root
redirect_stderr=true
stdout_logfile=/data/logs/kubernetes/kube-scheduler/scheduler.stdout.log
stdout_logfile_maxbytes=64MB
stdout_logfile_backups=4
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
8.8、启动kube-scheduler服务
supervisorctl update
supervisorctl status
8.9、其它节点安装kube-scheduler
把kube-scheduler启动脚本和supervisor配置文件拷贝到202和203主机
scp /opt/kubernetes/server/bin/kube-scheduler.sh hfqg1-202:/opt/kubernetes/server/bin/
scp /opt/kubernetes/server/bin/conf/kube-scheduler.sh hfqg1-203:/opt/kubernetes/server/bin/
scp /etc/supervisord.d/kube-scheduler.ini hfqg1-202:/etc/supervisord.d/
scp /etc/supervisord.d/kube-scheduler.ini hfqg1-203:/etc/supervisord.d/
8.10、修改名称并启动kube-scheduler服务
202服务器
203服务器
启动kube-scheduler服务
supervisorctl update
supervisorctl status
查看集群状态
kubectl get cs
查看集群资源
kubectl get sa -A
至此,kube-scheduler组件安装完成。
本文来自博客园,作者:霸都运维,转载请注明原文链接:https://www.cnblogs.com/wangjie20200529/p/16562610.html