您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
[root@master01 k8s]# cd /root/k8s/kubernetes/server/bin //进入之前解压好的软件命令目录
[root@master01 bin]# ls
apiextensions-apiserver kube-apiserver.docker_tag kube-proxy
cloud-controller-manager kube-apiserver.tar kube-proxy.docker_tag
cloud-controller-manager.docker_tag kube-controller-manager kube-proxy.tar
cloud-controller-manager.tar kube-controller-manager.docker_tag kube-scheduler
hyperkube kube-controller-manager.tar kube-scheduler.docker_tag
kubeadm kubectl kube-scheduler.tar
kube-apiserver kubelet mounter
[root@master01 bin]# scp kubelet kube-proxy root@192.168.80.13:/opt/kubernetes/bin/ //把 kubelet、 kube-proxy拷贝到node节点上去
root@192.168.80.13's password:
kubelet 100% 168MB 91.4MB/s 00:01
kube-proxy 100% 48MB 71.8MB/s 00:00
[root@master01 bin]# scp kubelet kube-proxy root@192.168.80.14:/opt/kubernetes/bin/
root@192.168.80.14's password:
kubelet 100% 168MB 122.5MB/s 00:01
kube-proxy 100% 48MB 95.2MB/s 00:00
[root@master01 bin]# scp /mnt/node.zip root@192.168.80.13:/root //将宿主机挂载的压缩文件拷贝到node01节点
root@192.168.80.13's password:
node.zip 100% 1240 4.1KB/s 00:00
[root@node01 ~]# ls
anaconda-ks.cfg flannel.sh flannel-v0.10.0-linux-amd64.tar.gz node.zip README.md
[root@node01 ~]# unzip node.zip //解压压缩包
Archive: node.zip
inflating: proxy.sh
inflating: kubelet.sh
master01节点操作
[root@master01 bin]# cd /root/k8s/
[root@master01 k8s]# mkdir kubeconfig //创建配置文件目录
[root@master01 k8s]# cd kubeconfig
[root@master01 kubeconfig]# cp /mnt/kubeconfig.sh /root/k8s/kubeconfig/ //拷贝脚本到配置文件目录
[root@master01 kubeconfig]# mv kubeconfig.sh kubeconfig //更名
[root@master01 kubeconfig]# vim kubeconfig //编辑文件
# 创建 TLS Bootstrapping Token
#BOOTSTRAP_TOKEN=$(head -c 16 /dev/urandom | od -An -t x | tr -d ' ')
BOOTSTRAP_TOKEN=0fb61c46f8991b718eb38d27b605b008
cat > token.csv <<EOF
${BOOTSTRAP_TOKEN},kubelet-bootstrap,10001,"system:kubelet-bootstrap"
EOF
//删除此部分内容
...
:wq
[root@master01 kubeconfig]# cat /opt/kubernetes/cfg/token.csv //查看token文件获取序列号即可
c37758077defd4033bfe95a071689272,kubelet-bootstrap,10001,"system:kubelet-bootstrap"
[root@master01 kubeconfig]# vim kubeconfig
...
# 设置客户端认证参数
kubectl config set-credentials kubelet-bootstrap \
--token=c37758077defd4033bfe95a071689272 \ //修改为tokenID 将变量更改为获取的序列号
--kubeconfig=bootstrap.kubeconfig
...
:wq
[root@master01 kubeconfig]# vim /etc/profile //编辑文件设置环境变量
...
export PATH=$PATH:/opt/kubernetes/bin/
:wq
[root@master01 kubeconfig]# source /etc/profile //重新执行文件
[root@master01 kubeconfig]# kubectl get cs //查看群集状态,确认群集正常
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}
etcd-1 Healthy {"health":"true"}
etcd-2 Healthy {"health":"true"}
[root@master01 kubeconfig]# bash kubeconfig 192.168.80.12 /root/k8s/k8s-cert/ //使用命令生成配置文件
Cluster "kubernetes" set.
User "kubelet-bootstrap" set.
Context "default" created.
Switched to context "default".
Cluster "kubernetes" set.
User "kube-proxy" set.
Context "default" created.
Switched to context "default".
[root@master01 kubeconfig]# ls
bootstrap.kubeconfig kubeconfig kube-proxy.kubeconfig //生成两个配置文件
[root@master01 kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.80.13:/opt/kubernetes/cfg/ //将生成的配置文件拷贝到node节点中
root@192.168.80.13's password:
bootstrap.kubeconfig 100% 2167 1.1MB/s 00:00
kube-proxy.kubeconfig 100% 6269 7.1MB/s 00:00
[root@master01 kubeconfig]# scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.80.14:/opt/kubernetes/cfg/
root@192.168.80.14's password:
bootstrap.kubeconfig 100% 2167 1.6MB/s 00:00
kube-proxy.kubeconfig 100% 6269 4.5MB/s 00:00
[root@master01 kubeconfig]# kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap //创建bootstrap角色赋予权限用于连接apiserver请求签名(关键点)
clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created
[root@node01 ~]# ls /opt/kubernetes/cfg/ //检查是否成功拷贝
bootstrap.kubeconfig flanneld kube-proxy.kubeconfig
[root@node01 ~]# bash kubelet.sh 192.168.80.13 //执行脚本文件生成kubelet的配置文件与启动脚本
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
[root@node01 ~]# systemctl status kubelet.service //查看服务是否启动
● kubelet.service - Kubernetes Kubelet
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-02-10 14:17:12 CST; 1min 45s ago //成功运行
Main PID: 79678 (kubelet)
Memory: 14.2M
...
[root@master01 kubeconfig]# kubectl get csr //查看是否有node01节点请求申请证书
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 3m16s kubelet-bootstrap Pending
[root@master01 kubeconfig]# kubectl certificate approve node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w //同意自签node01节点自签请求
certificatesigningrequest.certificates.k8s.io/node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w approved
[root@master01 kubeconfig]# kubectl get csr //同意后再次查看请求状态
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 4m40s kubelet-bootstrap Approved,Issued //已经被允许加入群集
[root@master01 kubeconfig]# kubectl get node //查看群集节点,成功加入node01节点
NAME STATUS ROLES AGE VERSION
192.168.80.13 Ready <none> 78s v1.12.3
[root@node01 ~]# bash proxy.sh 192.168.80.13 //执行脚本文件,启动kube-proxy服务并生成配置文件
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/ systemd/system/kube-proxy.service.
[root@node01 ~]# systemctl status kube-proxy.service //查看服务是否启动
● kube-proxy.service - Kubernetes Proxy
Loaded: loaded (/usr/lib/systemd/system/kube-proxy.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-02-10 14:23:59 CST; 1min 2s ago //成功启动
Main PID: 80889 (kube-proxy)
...
[root@node01 ~]# scp -r /opt/kubernetes/ root@192.168.80.14:/opt/ //把现成的/opt/kubernetes目录复制到node02节点进行修改即可
The authenticity of host '192.168.80.14 (192.168.80.14)' can't be established.
ECDSA key fingerprint is SHA256:Ih0NpZxfLb+MOEFW8B+ZsQ5R8Il2Sx8dlNov632cFlo.
ECDSA key fingerprint is MD5:a9:ee:e5:cc:40:c7:9e:24:5b:c1:cd:c1:7b:31:42:0f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.80.14' (ECDSA) to the list of known hosts.
root@192.168.80.14's password:
flanneld 100% 235 139.5KB/s 00:00
bootstrap.kubeconfig 100% 2167 4.6MB/s 00:00
kube-proxy.kubeconfig 100% 6269 14.2MB/s 00:00
kubelet 100% 377 430.7KB/s 00:00
kubelet.config 100% 267 262.3KB/s 00:00
kubelet.kubeconfig 100% 2296 3.3MB/s 00:00
kube-proxy 100% 189 299.2KB/s 00:00
mk-docker-opts.sh 100% 2139 2.3MB/s 00:00
scp: /opt//kubernetes/bin/flanneld: Text file busy
kubelet 100% 168MB 134.1MB/s 00:01
kube-proxy 100% 48MB 129.8MB/s 00:00
kubelet.crt 100% 2185 3.3MB/s 00:00
kubelet.key 100% 1675 2.8MB/s 00:00
kubelet-client-2020-02-10-14-21-18.pem 100% 1273 608.4KB/s 00:00
kubelet-client-current.pem 100% 1273 404.9KB/s 00:00
[root@node01 ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service root@192.168.80.14:/usr/lib/systemd/system/ //把kubelet,kube-proxy的service文件拷贝到node2中
root@192.168.80.14's password:
kubelet.service 100% 264 350.1KB/s 00:00
kube-proxy.service 100% 231 341.5KB/s 00:00
[root@node02 ~]# cd /opt/kubernetes/ssl/ //进入node01节点拷贝过来的证书目录
[root@node02 ssl]# rm -rf * //删除证书,稍后我们在重新申请证书
[root@node02 ssl]# cd ../cfg/ //进入配置文件目录
[root@node02 cfg]# vim kubelet //修改文件
KUBELET_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=192.168.80.14 \ //修改IP地址
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \
--config=/opt/kubernetes/cfg/kubelet.config \
--cert-dir=/opt/kubernetes/ssl \
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
:wq
[root@node02 cfg]# vim kubelet.config //修改配置文件
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 192.168.80.14 //修改IP地址
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2
clusterDomain: cluster.local.
failSwapOn: false
authentication:
anonymous:
enabled: true
:wq
[root@node02 cfg]# vim kube-proxy //修改kube-proxy配置文件
KUBE_PROXY_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=192.168.80.14 \ //修改IP地址
--cluster-cidr=10.0.0.0/24 \
--proxy-mode=ipvs \
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"
:wq
[root@node02 cfg]# systemctl start kubelet.service //启动服务
[root@node02 cfg]# systemctl enable kubelet.service //设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
[root@node02 cfg]# systemctl start kube-proxy.service //启动服务
[root@node02 cfg]# systemctl enable kube-proxy.service //设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/ systemd/system/kube-proxy.service.
[root@master01 kubeconfig]# kubectl get csr //查看node节点请求
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 22m kubelet-bootstrap Approved,Issued
node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 4m54s kubelet-bootstrap Pending //等待集群给该节点颁发证书
[root@master01 kubeconfig]# kubectl certificate approve node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 //使用命令授权许可加入群集
certificatesigningrequest.certificates.k8s.io/node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 approved
[root@master01 kubeconfig]# kubectl get csr //再次查看node节点请求
NAME AGE REQUESTOR CONDITION
node-csr-WQGufSR06MTCWv0Neu0AexyqBZ1UgFDM1qdSziNEq_w 23m kubelet-bootstrap Approved,Issued
node-csr-jUI3h8Ae2tC5OmihpylXEVlMiJnNO117Z1OgpopxAA0 5m58s kubelet-bootstrap Approved,Issued //成功加入
[root@master01 kubeconfig]# kubectl get node //查看群集中的节点
NAME STATUS ROLES AGE VERSION
192.168.80.13 Ready <none> 20m v1.12.3
192.168.80.14 Ready <none> 76s v1.12.3 //成功加入节点
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。