系统配置:

  • [master server:192.168.200.41]
  • [new node05 server:192.168.200.201]
  • [node1 server:192.168.200.51]
  • [api server:https://192.168.200.50:8443]
  • [4cpu]
  • [20G内存]
  • [50G系统硬盘]
  • [500G数据盘]
1、初始化系统
#修改hostname
vim /etc/hostname
xxxxx

hostname xxxxx


#master节点上 在所有master node节点中添加新node的hosts信息
vim /etc/hosts
192.168.200.201  k8s-node-05

# 格式化硬盘2 挂载到/data
mkdir   /data
fdisk -l #查看要分配给/data的数据盘我这里是/dev/sdb
fdisk /dev/sdb 
依次输入n,p,回车,回车,回车,w
mkfs.xfs  /dev/sdb1
mount  /dev/sdb1    /data
echo "/dev/sdb1  /data           xfs     defaults   0 0" >>/etc/fstab

#添加docker仓库登录配置秘钥
mkdir  /root/.docker
cat /root/.docker/config.json <<EOF
{
        "auths": {
                "registry.cn-hangzhou.aliyuncs.com": {
                        "auth": "5p2t5bee5bCP5a2Q572R57uc56eR5oqAOld1emloYW8xMDEy"
                }
        },
        "HttpHeaders": {
                "User-Agent": "Docker-Client/18.09.6 (linux)"
        }
}
EOF





echo '* soft nofile 190000' >> /etc/security/limits.conf
echo '* hard nofile 200000' >> /etc/security/limits.conf
echo '* soft nproc 252144' >> /etc/security/limits.conf
echo '* hadr nproc 262144' >> /etc/security/limits.conf
2、关闭防火墙,SELINUX,关闭SWAP分区,配置IPTABLES,建立对应的目录,添加用户,调整内核参数,安装必要的软件等等
systemctl stop firewalld
systemctl disable firewalld
chkconfig firewalld off
setenforce 0
sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config

swapoff -a
sed -i '/ swap /d' /etc/fstab 
modprobe br_netfilter
modprobe ip_vs	


iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -P FORWARD ACCEPT

useradd  docker  -s /bin/nologin

cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF

#复制内核参数文件到sysctl.d目录下
cp kubernetes.conf  /etc/sysctl.d/kubernetes.conf
#应用当前配置
sysctl -p /etc/sysctl.d/kubernetes.conf
mount -t cgroup -o cpu,cpuacct  /sys/fs/cgroup/cpu,cpuacct

#添加系统必要依赖
yum install -y epel-release
yum install -y conntrack ipvsadm ipset jq sysstat curl iptables libseccomp vim socat
3、添加docker仓库配置
mkdir -p  /etc/docker/

cat  /etc/docker/daemon.json <<eof
{
        "registry-mirrors": ["https://y3t33cqw.mirror.aliyuncs.com","https://4664hm12.mirror.aliyuncs.com","https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com"],
        "insecure-registries": ["docker02:35000"],
        "max-concurrent-downloads": 20,
        "live-restore": true,
        "max-concurrent-uploads": 10,
        "debug": true,
        "data-root": "/data/docker/data",
        "exec-root": "/data/docker/exec",
        "log-opts": {
                "max-size": "100m",
                "max-file": "5"
        }
}
eof
4、从原有的node节点上拷贝执行文件、服务
#k8s相关
scp -r root@192.168.200.51:/data/k8s   /data/
scp -r root@192.168.200.51:/data/kubernetes   /data/
chmod -R a+x /data/k8s/bin
scp -r root@192.168.200.51:/etc/kubernetes   /etc/
scp -r root@192.168.200.51:/root/.kube/config   /root/ 

#flanneld
scp -r root@192.168.200.51:/etc/flanneld /etc/


#service
scp -r root@192.168.200.51:/etc/systemd/system/{docker.service,flanneld.service,kubelet.service,kube-proxy.service}     /usr/lib/systemd/system/

#添加执行文件的系统环境

echo 'PATH=/data/k8s/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin' >>/root/.bashrc
#删除旧证书
rm  /etc/kubernetes/kubelet-client-current.pem
rm  /etc/kubernetes/kubelet-server-current.pem

修改/etc/kubernetes/kubelet-config.yaml中的原始node ip地址

修改/etc/systemd/system/kubelet.service 中的node id相关配置

5、在master节点上创建token
# 创建 token
    export BOOTSTRAP_TOKEN=$(kubeadm token create \
    --description kubelet-bootstrap-token \
     --groups system:bootstrappers:m1 \
     --kubeconfig ~/.kube/config)
    # 设置集群参数
    kubectl config set-cluster kubernetes \
      --certificate-authority=/etc/kubernetes/cert/ca.pem \
      --embed-certs=true \
      --server=https://192.168.200.50:8443#api server地址 \
      --kubeconfig=kubelet-bootstrap.kubeconfig
    # 设置客户端认证参数
    kubectl config set-credentials kubelet-bootstrap \
      --token=${BOOTSTRAP_TOKEN} \
      --kubeconfig=kubelet-bootstrap.kubeconfig
    # 设置上下文参数
    kubectl config set-context default \
      --cluster=kubernetes \
      --user=kubelet-bootstrap \
      --kubeconfig=kubelet-bootstrap.kubeconfig
    # 设置默认上下文
    kubectl config use-context default --kubeconfig=kubelet-bootstrap.kubeconfig

把当前目录下kubelet-bootstrap.kubeconfig 拷贝到客户端节点/etc/kubernetes/下替换旧证书
api server地址可以通过执行kubectl cluster-info 查看


 
#启动服务 
systemctl daemon-reload
systemctl enable flanneld docker kubelet kube-proxy
systemctl restart flanneld docker kubelet kube-proxy
6、master服务器 签证证书

#master上签证证书
kubectl get csr #如果无法看到node申请证书 在node节点上执行journalctl -u kubelet 和systemctl status -l kubelet 查看报错解决

kubectl certificate approve  csr6h9J #`csr6h9J`是证书的代码 在上一步中有显示的第一列数字
#master上执行
kubectl get node

此时node已经加入进来了

#相关服务操作命令
systemctl daemon-reload
systemctl enable flanneld docker kubelet kube-proxy
systemctl restart flanneld docker kubelet kube-proxy
systemctl start flanneld docker kubelet kube-proxy
systemctl stop flanneld docker kubelet kube-proxy
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐