[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 <
[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 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 20m v1.12.3
192.168.80.14 Ready 76s v1.12.3 //成功加入节点