k8s服务端二进制部署-kube-scheduler

本文章是 k8s二进制高可用集群部署 的分支。详细步骤请参考目录。

二进制下载地址 参考 k8s服务端二进制部署-kube-apiserver

1.使用自签CA签发kube-scheduler证书

  在etcd集群部署及kube-apiserver流程中我们已经自签了证书签发机构(CA)

  因此建议如果etcd和kube-apiserver使用的证书使用了相同的CA签发,那么继续使用相同

  如果不相同则使用kube-apiserver使用的CA签发kube-controller-manager的证书

cat > kube-scheduler-csr.json << EOF
{
    "CN": "system:kube-scheduler",
    "hosts": [
        "10.0.0.1",
        "127.0.0.1",
        "192.168.64.130",
        "192.168.64.131",
        "192.168.64.132",
        "192.168.64.133",
        "192.168.64.134",
        "10.10.10.1",
        "10.255.0.1",
        "kubernetes",
        "kubernetes.default",
        "kubernetes.default.svc",
        "kubernetes.default.svc.cluster",
        "kubernetes.default.svc.cluste.local"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
      {
        "C": "CN",
        "ST": "Tianjin",
        "L": "Tianjin",
        "O": "system:kube-scheduler",
        "OU": "System"
      }
    ]
}
EOF

# 生成证书
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kube-scheduler-csr.json | cfssljson -bare kube-scheduler

  注:

    hosts 列表包含所有 kube-scheduler 节点 IP;
    CN 为 system:kube-scheduler、O 为 system:kube-scheduler,kubernetes 内置的 ClusterRoleBindings system:kube-scheduler 将赋予 kube-scheduler 工作所需的权限。

 2.生成kubeconfig文件(以下是shell命令,直接在终端执行)【kubeconfig介绍

cd /opt/kubernetes

 

KUBE_CONFIG="/opt/kubernetes/cfg/kube-scheduler.kubeconfig"
KUBE_APISERVER="https://192.168.64.130:6443"

#设置集群参数
kubectl config set-cluster kubernetes \
  --certificate-authority=/opt/kubernetes/ssl/ca.pem \
  --embed-certs=true \
  --server=${KUBE_APISERVER} \
  --kubeconfig=${KUBE_CONFIG}
  
#设置客户端认证参数
kubectl config set-credentials system:kube-scheduler \
  --client-certificate=/opt/kubernetes/ssl/kube-scheduler.pem \
  --client-key=/opt/kubernetes/ssl/kube-scheduler-key.pem \
  --embed-certs=true \
  --kubeconfig=${KUBE_CONFIG}
  
#设置上下文参数
kubectl config set-context system:kube-scheduler \
  --cluster=kubernetes \
  --user=system:kube-scheduler \
  --kubeconfig=${KUBE_CONFIG}
  
#设置默认上下文
kubectl config use-context system:kube-scheduler --kubeconfig=${KUBE_CONFIG}

3.创建配置文件

cat > /opt/kubernetes/cfg/kube-scheduler.conf << EOF
KUBE_SCHEDULER_OPTS="--bind-address=127.0.0.1 \
--kubeconfig=/opt/kubernetes/cfg/kube-scheduler.kubeconfig \
--leader-elect=true \
--v=2"
EOF

  参数说明:

    --kubeconfig:连接apiserver配置文件

    --leader-elect:当该组件启动多个时,自动选举(HA)

4.systemd管理scheduler

cat > /usr/lib/systemd/system/kube-scheduler.service << EOF
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=/opt/kubernetes/cfg/kube-scheduler.conf
ExecStart=kube-scheduler \$KUBE_SCHEDULER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

5.启动并设置开机启动

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

 

posted @ 2023-02-21 18:06  SpringCore  阅读(137)  评论(0编辑  收藏  举报