kube-scheduler为master节点组件。kube-scheduler集群包含 3 个节点,启动后将通过竞争选举机制产生一个 leader 节点,其它节点为阻塞状态。当 leader 节点不可用后,剩余节点将再次进行选举产生新的 leader 节点,从而保证服务的高可用性。
成都创新互联公司总部坐落于成都市区,致力网站建设服务有成都网站设计、做网站、成都外贸网站建设公司、网络营销策划、网页设计、网站维护、公众号搭建、微信小程序、软件开发等为企业提供一整套的信息化建设解决方案。创造真正意义上的网站建设,为互联网品牌在互动行销领域创造价值而不懈努力!
特别说明:这里所有的操作都是在devops这台机器上通过ansible工具执行;kube-scheduler 在如下两种情况下使用该证书:
#################### Variable parameter setting ######################
KUBE_NAME=kube-scheduler
K8S_INSTALL_PATH=/data/apps/k8s/kubernetes
K8S_BIN_PATH=${K8S_INSTALL_PATH}/sbin
K8S_LOG_DIR=${K8S_INSTALL_PATH}/logs
K8S_CONF_PATH=/etc/k8s/kubernetes
KUBE_CONFIG_PATH=/etc/k8s/kubeconfig
CA_DIR=/etc/k8s/ssl
SOFTWARE=/root/software
VERSION=v1.14.2
PACKAGE="kubernetes-server-${VERSION}-linux-amd64.tar.gz"
DOWNLOAD_URL=“”https://github.com/devops-apps/download/raw/master/kubernetes/${PACKAGE}"
ETH_INTERFACE=eth2
LISTEN_IP=$(ifconfig | grep -A 1 ${ETH_INTERFACE} |grep inet |awk '{print $2}')
USER=k8s
访问kubernetes github 官方地址下载稳定的 realease 包至本机;
wget $DOWNLOAD_URL -P $SOFTWARE
将kubernetes 软件包分发到各个master节点服务器;
sudo ansible master_k8s_vgs -m copy -a "src=${SOFTWARE}/$PACKAGE dest=${SOFTWARE}/" -b
### 1.Check if the install directory exists.
if [ ! -d "$K8S_BIN_PATH" ]; then
mkdir -p $K8S_BIN_PATH
fi
if [ ! -d "$K8S_LOG_DIR/$KUBE_NAME" ]; then
mkdir -p $K8S_LOG_DIR/$KUBE_NAME
fi
if [ ! -d "$K8S_CONF_PATH" ]; then
mkdir -p $K8S_CONF_PATH
fi
if [ ! -d "$KUBE_CONFIG_PATH" ]; then
mkdir -p $KUBE_CONFIG_PATH
fi
### 2.Install kube-apiserver binary of kubernetes.
if [ ! -f "$SOFTWARE/kubernetes-server-${VERSION}-linux-amd64.tar.gz" ]; then
wget $DOWNLOAD_URL -P $SOFTWARE >>/tmp/install.log 2>&1
fi
cd $SOFTWARE && tar -xzf kubernetes-server-${VERSION}-linux-amd64.tar.gz -C ./
cp -fp kubernetes/server/bin/$KUBE_NAME $K8S_BIN_PATH
ln -sf $K8S_BIN_PATH/$KUBE_NAM /usr/local/bin
chown -R $USER:$USER $K8S_INSTALL_PATH
chmod -R 755 $K8S_INSTALL_PATH
cd ${CA_DIR}
sudo ansible master_k8s_vgs -m copy -a "src=kube-scheduler.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m copy -a "src=kube-scheduler-key.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m copy -a "src=ca.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m copy -a "src=ca-key.pem dest=${CA_DIR}/" -b
kube-scheduler使用 kubeconfig文件连接访问 apiserver服务,该文件提供了 apiserver 地址、嵌入的 CA 证书和 kube-scheduler证书:
cd $KUBE_CONFIG_PATH
sudo ansible master_k8s_vgs -m copy -a \
"src=kube-scheduler.kubeconfig dest=$KUBE_CONFIG_PATH/" -b
备注: 如果在前面小节已经同步过各组件kubeconfig和证书文件,此处可以不必执行此操作;
cat >${K8S_CONF_PATH}/kube-scheduler.yaml<
cat >/usr/lib/systemd/system/${KUBE_NAME}.service<
systemctl status kube-scheduler|grep Active
确保状态为 active (running),否则查看日志,确认原因:
sudo journalctl -u kube-scheduler
注意:以下命令在 kube-scheduler 节点上执行。kube-scheduler 监听 10251 和 10251 端口:两个接口都对外提供 /metrics 和 /healthz 的访问。
sudo netstat -ntlp | grep kube-sc
tcp 0 0 127.0.0.1:10251 0.0.0.0:* LISTEN 28786/kube-schedule
tcp 0 0 10.10.10.22:10259 0.0.0.0:* LISTEN 28786/kube-schedule
注意:很多安装文档都是关闭了非安全端口,将安全端口改为默认的非安全端口数值,这会导致查看集群状态是报下面所示的错误,执行 kubectl get cs命令时,apiserver 默认向 127.0.0.1 发送请求。当controller-manager、scheduler以集群模式运行时,有可能和kube-apiserver不在一台机器上,且访问方式为https,则 controller-manager或scheduler 的状态为 Unhealthy,但实际上它们工作正常。则会导致上述error,但实际集群是安全状态;
kubectl get componentstatuses
NAME STATUS MESSAGE ERROR
controller-manager Unhealthy dial tcp 127.0.0.1:10252: connect: connection refused
scheduler Unhealthy dial tcp 127.0.0.1:10251: connect: connection refused
etcd-0 Healthy {"health":"true"}
etcd-2 Healthy {"health":"true"}
etcd-1 Healthy {"health":"true"}
正常输出应该为:
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-2 Healthy {"health":"true"}
etcd-1 Healthy {"health":"true"}
etcd-0 Healthy {"health":"true"}
kubectl get endpoints kube-scheduler --namespace=kube-system -o yaml
随机找一个或两个 master 节点,停掉 kube-scheduler 服务,看其它节点是否获取了 leader 权限.
kube-scheduler部署完后,整个kubernetes集群master节点部署完成,后面还需要要部署node节点相关主机,关于kube-scheduler脚本请从此处获取;