k8s--node节点安装
#1、更改所有节点的主机名,便于区分(各自执行):hostnamectl set-hostname k8s-node1#2、立即生效:bash# 3、查看主机名:hostname#4、所以节点关闭防火墙:systemctl stop firewalldsystemctl disable firewalld#5、所有节点关闭selinux:sed -i "s/SELINUX=enforcing/SE
#1、更改所有节点的主机名,便于区分(各自执行):
hostnamectl set-hostname k8s-node1
#2、立即生效:
bash
# 3、查看主机名:
hostname
#4、所以节点关闭防火墙:
systemctl stop firewalld
systemctl disable firewalld
#5、所有节点关闭selinux:
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
#6、所有节点关闭swap:
swapoff -a # 临时关闭
cat /etc/fstab 注释到swap那一行 # 永久关闭
sed -i 's/.*swap.*/#&/g' /etc/fstab
#7、所有节点添加主机名与IP对应关系(所有机器执行):
cat >> /etc/hosts << EOF
10.0.12.16 k8s-master
10.0.16.7 k8s-node-1
10.0.16.17 k8s-node-2
EOF
#8、同步时间(可选):
yum install ntpdate -y
ntpdate ntp.api.bz
#9、将桥接的IPv4流量传递到iptables的链(所有机器执行)
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
#10、所有节点安装docker:
yum -y install wget
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-20.10.9-3.el7
# 启动docker,并设置docker开机自启
systemctl start docker
systemctl enable docker
# 配置加速,并设置驱动
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://6ze43vnb.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
# 加载daemon并重启docker
systemctl daemon-reload
systemctl restart docker
#11、所有节点添加阿里云YUM源:
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
#12、所有节点安装kubeadm,kubelet和kubectl:
yum install -y kubelet-1.23.1 kubeadm-1.23.1 kubectl-1.23.1
systemctl enable kubelet
#13、将node节点加入到集群:
# 执行成功会输出下面的数据,将下面的数据拷贝到从节点执行(每次都不一样根据自己实际生成的为准,这个是node节点加入集群使用)
kubeadm join 10.0.12.16:6443 --token 5gdxmq.mk0zpdgbqnxqg6rz \
--discovery-token-ca-cert-hash sha256:28d0f65cf2c8fae3ebdbea3244be273cbb2f1807d327b0be9c8427feeb8a5313
# 查看各节点是否连接上主节点
kubectl get nodes
#Node节点出现这个报错:The connection to the server localhost:8080 was refused - did you specify the right host or port?
解决如下:
#在Master节点运行下面命令将admin.conf文件拷贝到从节点:
sudo scp /etc/kubernetes/admin.conf root@42.192.136.115:~
#在Node节点运行下面命令配置环境变量:
export KUBECONFIG=$HOME/admin.conf
#14、安装Pod网络插件(CNI):
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl create -f kube-flannel.yml
# 查看pods节点信息(所有节点的状态为:Running,说明正常)
kubectl get pods -n kube-system
更多推荐
所有评论(0)