【容器化】Kubernetes二进制高可用部署6-Kube-Controller和kube-Scheduler部署

零、目录

一、说明

本文将部署Kubernetes组件kube-controller和kube-scheduler。

二、Kubernetes客户端证书生成

kube-controller-manager、kube-scheduler、kubelet和kube-proxy服务作为客户端连接kube-apiserver服务,需要为它们创建客户端CA证书进行访问。

1
2
3
4
5
# 192.168.56.105节点执行
openssl genrsa -out /etc/kubernetes/pki/client.key 2048
# 其中 -subj 参数中的 "/CN" 的名称可以被设置为 "admin",用于标识连接 kube-apiserver 的客户端用户名称
openssl req -new -key /etc/kubernetes/pki/client.key -subj "/CN=admin" -out /etc/kubernetes/pki/client.csr
openssl x509 -req -in /etc/kubernetes/pki/client.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out /etc/kubernetes/pki/client.crt -days 36500
1
2
# 192.168.56.106和192.168.56.107节点执行
scp -r root@192.168.56.105:/etc/kubernetes/pki/client.* /etc/kubernetes/pki/

三、创建kubeconfig配置文件

统一创建一个kubeconfig文件作为kube-controller-manager、kube-scheduler、kubelet和kube-proxy服务连接kube-apiserver服务的配置文件,也作为后续kubectl命令工具连接kube-apiserver服务的配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 所有节点执行
cat << EOF > /etc/kubernetes/kubeconfig
apiVersion: v1
kind: Config
clusters:
- name: default
cluster:
server: https://192.168.56.250:9443
certificate-authority: /etc/kubernetes/pki/ca.crt
users:
- name: admin
user:
client-certificate: /etc/kubernetes/pki/client.crt
client-key: /etc/kubernetes/pki/client.key
contexts:
- context:
cluster: default
user: admin
name: default
current-context: default
EOF

四、复制二进制文件到/usr/bin目录

1
2
3
# 所有节点执行
cp /usr/local/src/kubernetes/server/bin/kube-controller-manager /usr/bin/
cp /usr/local/src/kubernetes/server/bin/kube-scheduler /usr/bin/

创建kube-controller服务

创建kube-controller配置文件

1
2
3
4
5
6
7
8
9
# 所有节点执行
cat << EOF > /etc/kubernetes/controller-manager.conf
KUBE_CONTROLLER_MANAGER_ARGS="--kubeconfig=/etc/kubernetes/kubeconfig \
--leader-elect=true \
--service-cluster-ip-range=169.169.0.0/16 \
--service-account-private-key-file=/etc/kubernetes/pki/apiserver.key \
--root-ca-file=/etc/kubernetes/pki/ca.crt \
--log-dir=/var/log/kubernetes --logtostderr=false --v=0"
EOF

创建系统服务文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 所有节点执行
cat << EOF > /usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=/etc/kubernetes/controller-manager.conf
ExecStart=/usr/bin/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_ARGS
Restart=always

[Install]
WantedBy=multi-user.target
EOF

启动kube-controller服务

1
2
3
4
# 所有节点执行
systemctl daemon-reload
systemctl start kube-controller-manager
systemctl enable kube-controller-manager

五、创建kube-scheduler服务

创建kube-scheduler配置文件

1
2
3
4
5
6
# 所有节点执行
cat << EOF > /etc/kubernetes/scheduler.conf
KUBE_SCHEDULER_ARGS="--kubeconfig=/etc/kubernetes/kubeconfig \
--leader-elect=true \
--log-dir=/var/log/kubernetes --logtostderr=false --v=0"
EOF

创建系统服务文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 所有节点执行
cat << EOF > /usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=/etc/kubernetes/scheduler.conf
ExecStart=/usr/bin/kube-scheduler \$KUBE_SCHEDULER_ARGS
Restart=always

[Install]
WantedBy=multi-user.target
EOF

启动kube-scheduler服务

1
2
3
4
# 所有节点执行
systemctl daemon-reload
systemctl start kube-scheduler
systemctl enable kube-scheduler

(•̀ᴗ•́)و ̑̑

Share