虚拟机安装k8s

k8s集群

参考

配置环境

#关闭selinux(管安全的)
sed -i 's/enforcing/disabled/' /etc/selinux/config

#关闭swap(类似虚拟内存,会有性能和管理问题)
swapoff -a 
sed -ri 's/.*swap.*/#&/' /etc/fstab   


#添加host
cat >> /etc/hosts << EOF
192.168.114.134 key01
192.168.114.135 key02
192.168.114.136 key03

EOF

#将桥接的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




#docker 加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://8gp5eki7.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker


#安装k8s(kubernetes)
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet-1.20.15 kubeadm-1.20.15 kubectl-1.20.15
systemctl enable kubelet && systemctl start kubelet

安装kubeadm


#master执行安装

kubeadm init \
  --apiserver-advertise-address=192.168.114.134  \
  --image-repository=registry.aliyuncs.com/google_containers \
  --kubernetes-version=v1.20.15 \
  --service-cidr=10.96.0.0/12 \
  --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all 

执行完master会提示

image-20230526160153692

在node上执行

kubeadm join 192.168.114.134:6443 --token fzd0li.4zuloza3grx9dsz9
--discovery-token-ca-cert-hash sha256:022004fbdafa83e172e030fc9195b0c41a020a82f18c2a4d65424e0173b9b8db

#使用kubectl工具,查看节点
mkdir -p $HOME/.kubernetes
cp -i /etc/kubernetes/admin.conf $HOME/.kubernetes/config
chown $(id -u):$(id -g) $HOME/.kubernetes/config
kubectl get nodes

接下来会有些异常情况,直接看参考链接解决即可

升级docker

yum -y remove docker*

yum install -y yum-utils device-mapper-persistent-data lvm2 
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum install docker-ce -y

service docker start

posted on 2023-05-26 16:25  隨風.NET  阅读(46)  评论(0编辑  收藏  举报

导航