一、配置apiserver
1.生成启动文件
cat > /usr/lib/systemd/system/kube-apiserver.service <<EOF [Unit] Description=Kubernetes API Server Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/etc/kubernetes/kube-apiserver ExecStart=/usr/bin/kube-apiserver $KUBE_APISERVER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target EOF
2.生成配置变量文件
cat >/etc/kubernetes/kube-apiserver<<EOF KUBE_APISERVER_OPTS="--logtostderr=false \ --v=4 \ --audit-log-maxage=30 \ --audit-log-maxbackup=3 \ --audit-log-maxsize=100 \ --audit-log-path=/opt/mflogs/kube-apiserver/kube-apiserver.log \
--log-dir=/opt/mflogs/kube-apiserver \ --etcd-servers=https://172.18.6.39:2379,https://172.18.6.40:2379,https://172.18.6.41:2379 \ --insecure-bind-address=0.0.0.0 \ --bind-address=172.18.6.39 \ --insecure-port=8080 \ --secure-port=6443 \ --advertise-address=172.18.6.39 \ --allow-privileged=true \ --service-cluster-ip-range=172.30.0.0/16 \ --admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota,NodeRestriction --authorization-mode=RBAC,Node \ --kubelet-https=true \ --enable-bootstrap-token-auth \ --token-auth-file=/etc/kubernetes/token.csv \ --service-node-port-range=30000-50000 \ --tls-cert-file=/etc/kubernetes/ssl/server.pem \ --tls-private-key-file=/etc/kubernetes/ssl/server-key.pem \ --client-ca-file=/etc/kubernetes/ssl/ca.pem \ --service-account-key-file=/etc/kubernetes/ssl/ca-key.pem \ --etcd-cafile=/etc/kubernetes/ssl/ca.pem \ --etcd-certfile=/etc/kubernetes/ssl/server.pem \ --etcd-keyfile=/etc/kubernetes/ssl/server-key.pem" EOF
3.启动服务
# systemctl start kube-apiserver
# systemctl enable kube-apiserver
二、配置kube-controller-manager
1.生成启动文件
cat > /usr/lib/systemd/system/kube-controller-manager.service <<EOF [Unit] Description=Kubernetes Controller Manager Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/etc/kubernetes/kube-controller-manager ExecStart=/usr/bin/kube-controller-manager $KUBE_CONTROLLER_MANAGER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target EOF
2.生成变量配置文件
cat > /etc/kubernetes/kube-controller-manager <<EOF KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=false \ --v=4
--log-dir=/opt/mflogs/kube-controller-manager \ --master=127.0.0.1:8080 \ --leader-elect=true \ --address=127.0.0.1 \ --service-cluster-ip-range=172.30.0.0/16 \ --cluster-name=kubernetes \ --cluster-signing-cert-file=/etc/kubernetes/ssl/ca.pem \ --cluster-signing-key-file=/etc/kubernetes/ssl/ca-key.pem \ --service-account-private-key-file=/etc/kubernetes/ssl/ca-key.pem \ --root-ca-file=/etc/kubernetes/ssl/ca.pem" EOF
3.启动服务
# systemctl start kube-controller-manager
# systemctl enable kube-controller-manager
三、配置scheduler
1.生成启动文件
cat > /usr/lib/systemd/system/kube-scheduler.service <<EOF [Unit] Description=Kubernetes Scheduler Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/etc/kubernetes/kube-scheduler ExecStart=/usr/bin/kube-scheduler $KUBE_SCHEDULER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target
EOF
2.配置参数配置文件
cat > /etc/kubernetes/kube-scheduler <<EOF KUBE_SCHEDULER_OPTS="--logtostderr=false \ --v=4 \
--log-dir=/opt/mflogs/kube-scheduler \ --master=127.0.0.1:8080 \ --leader-elect" EOF
3.启动服务
# systemctl start kube-scheduler
# systemctl enable kube-scheduler
四、查看master节点集群组件状态
kubectl get cs NAME STATUS MESSAGE ERROR controller-manager Healthy ok scheduler Healthy ok etcd-2 Healthy {"health": "true"} etcd-0 Healthy {"health": "true"} etcd-1 Healthy {"health": "true"}