请先阅读《手把手二进制安装K8S教程:第六章《Node部署flannel网络》》
登陆master 生成证书
cd /app/kubernetes
kubectl create clusterrolebinding kubelet-bootstrap \
--clusterrole=system:node-bootstrapper \
--user=kubelet-bootstrap
kubectl create clusterrolebinding kubelet-nodes \
--clusterrole=system:node \
--group=system:nodes
同步给node节点
scp -rp token.csv bootstrap.kubeconfig 192.168.75.131:/app/kubernetes/
scp -rp token.csv bootstrap.kubeconfig 192.168.75.132:/app/kubernetes/
192.168.75.131 Node 进行
192.168.75.132 Node 进行
node操作
mkdir /var/lib/kubelet
cd /app/kubernetes
cp -r ./server/bin/{kube-proxy,kubelet} /usr/local/bin/
vi /app/kubernetes/kubelet
###
## kubernetes kubelet (minion) config
#
## The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=192.168.75.131"
#
## The port for the info server to serve on
#KUBELET_PORT="--port=10250"
#
## You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=192.168.75.131"
#
## location of the api-server
## COMMENT THIS ON KUBERNETES 1.8+
#KUBELET_API_SERVER="--api-servers=http://192.168.75.130:8080"
#
## pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=lcb.docker.com:5000/pause-amd64:3.0"
#
## Add your own!
KUBELET_ARGS="--cgroup-driver=systemd --cluster-dns=10.254.0.2 --bootstrap-kubeconfig=/app/kubernetes/bootstrap.kubeconfig --kubeconfig=/app/kubernetes/kubelet.kubeconfig --cert-dir=/app/kubernetes/ssl --cluster-domain=cluster.local --hairpin-mode promiscuous-bridge --serialize-image-pulls=false"
vim /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/app/kubernetes/config
EnvironmentFile=-/app/kubernetes/kubelet
ExecStart=/usr/local/bin/kubelet \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBELET_API_SERVER \
$KUBELET_ADDRESS \
$KUBELET_PORT \
$KUBELET_HOSTNAME \
$KUBE_ALLOW_PRIV \
$KUBELET_POD_INFRA_CONTAINER \
$KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动kublet
systemctl daemon-reload
systemctl enable kubelet
systemctl start kubelet
systemctl status kubelet
配置 kube-proxy
vim /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
EnvironmentFile=-/app/kubernetes/config
EnvironmentFile=-/app/kubernetes/proxy
ExecStart=/usr/local/bin/kube-proxy \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_MASTER \
$KUBE_PROXY_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
vi /app/kubernetes/proxy
###
# kubernetes proxy config
# default config should be adequate
# Add your own!
KUBE_PROXY_ARGS="--bind-address=192.168.75.131 --hostname-override=192.168.75.131 --kubeconfig=/app/kubernetes/kube-proxy.kubeconfig --cluster-cidr=10.254.0.0/16"
启动 kube-proxy
systemctl daemon-reload
systemctl enable kube-proxy
systemctl start kube-proxy
systemctl status kube-proxy
master操作
kubectl get csr
master操作添加node节点
kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-7Wogeh5AfZSoNLGxYtFYgFjFapDJ6pGAftIY-yfkawY 22m kubelet-bootstrap Pending
kubectl certificate approve node-csr-7Wogeh5AfZSoNLGxYtFYgFjFapDJ6pGAftIY-yfkawY
certificatesigningrequest.certificates.k8s.io/node-csr-7Wogeh5AfZSoNLGxYtFYgFjFapDJ6pGAftIY-yfkawY approved
报错及解决:
kubelet.service - Kubernetes Kubelet Server
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since 二 2019-04-23 19:35:21 CST; 39s ago
Docs: https://github.com/GoogleCloudPlatform/kubernetes
Process: 66951 ExecStart=/usr/local/bin/kubelet $KUBE_LOGTOSTDERR $KUBE_LOG_LEVEL $KUBELET_API_SERVER $KUBELET_ADDRESS $KUBELET_PORT $KUBELET_HOSTNAME $KUBE_ALLOW_PRIV $KUBELET_POD_INFRA_CONTAINER $KUBELET_ARGS (code=exited, status=255)
Main PID: 66951 (code=exited, status=255)
4月 23 19:35:21 node01 kubelet[66951]: --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
4月 23 19:35:21 node01 kubelet[66951]: --volume-plugin-dir string The full path of the directory in which to search for additi...s/volume/exec/")
4月 23 19:35:21 node01 kubelet[66951]: --volume-stats-agg-period duration Specifies interval for kubelet to calculate and cache the volume disk usage ...
4月 23 19:35:21 node01 kubelet[66951]: F0423 19:35:21.341359 66951 server.go:148] unknown flag: --require-kubeconfig
4月 23 19:35:21 node01 systemd[1]: kubelet.service holdoff time over, scheduling restart.
4月 23 19:35:21 node01 systemd[1]: Stopped Kubernetes Kubelet Server.
4月 23 19:35:21 node01 systemd[1]: start request repeated too quickly for kubelet.service
4月 23 19:35:21 node01 systemd[1]: Failed to start Kubernetes Kubelet Server.
4月 23 19:35:21 node01 systemd[1]: Unit kubelet.service entered failed state.
4月 23 19:35:21 node01 systemd[1]: kubelet.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
解决:unknown flag: --require-kubeconfig。这说明kubelet的启动参数中出现了一个它不认的flag。将该参数去掉即可。
重启kublet
systemctl daemon-reload
systemctl start kubelet
systemctl status kubelet
报错
The connection to the server localhost:8080 was refused - did you specify the right host or port?
输入:
kubectl proxy --port=8080
解决:master依次重启api-server controller,Node依次重启 flannel docker kubelet kube-proxy
以上内容参考:
https://jimmysong.io/kubernetes-handbook/practice/node-installation.html
作者留言:本人也是刚开始接触K8S,如果网友通过本人的教程如果有什么问题欢迎留言,一起排错,互相学习,共同进步!