k8s--master节点安装
#1、更改所有节点的主机名,便于区分(各自执行):hostnamectl set-hostname k8s-master#2、立即生效:bash# 3、查看主机名:hostname#4、所以节点关闭防火墙:systemctl stop firewalldsystemctl disable firewalld#5、所有节点关闭selinux:sed -i "s/SELINUX=enforcing/S
#1、更改所有节点的主机名,便于区分(各自执行):
hostnamectl set-hostname k8s-master
#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、可提前下载k8s所需要的容器(可选-master节点):
# 查看所需要的容器
kubeadm config images list
# 国外环境:下载所需要的容器
kubeadm config images pull
# --- 或 ---
# 国内环境:使用阿里云镜像仓库下载(国内环境该命令可不执行,下步骤kubeadm init已经默认为国内环境):
kubeadm config
images=(
kube-apiserver:v1.23.1
kube-controller-manager:v1.23.1
kube-scheduler:v1.23.1
kube-proxy:v1.23.1
pause:3.2
etcd:3.4.3-0
coredns:1.6.7
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/${image} k8s.gcr.io/${imageName}
done
[root@k8s-master ~]# docker images
#14、初始化master节点:
kubeadm init --apiserver-advertise-address=10.0.12.16 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.1 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
# 执行成功会输出下面的数据,将下面的数据拷贝到从节点执行(每次都不一样根据自己实际生成的为准,这个是node节点加入集群使用)
kubeadm join 10.0.12.16:6443 --token 5gdxmq.mk0zpdgbqnxqg6rz \
--discovery-token-ca-cert-hash sha256:28d0f65cf2c8fae3ebdbea3244be273cbb2f1807d327b0be9c8427feeb8a5313
# 在master节点执行
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# 查看各节点是否连接上主节点
kubectl get nodes
#15、安装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)