k8s安装
说明
本事件适合刚刚装系统的新机子,前提是可以ping通www.baidu。yum可以下载软件
本实验模拟单机k8s,主机ip为172.26.50.222
关闭防火墙
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
getenforce
setenforce 0
vim /etc/sysconfig/selinux 修改为disabled
iptables -F
关闭swap分区
记得重启使其生效,否则后面进行初始化会提示
vim /etc/fstab 注释swap
reboot
修改主机名
hostnamectl set-hostname k8s-master
将IP主机名写入主机清单
cat >> /etc/hosts << EOF
172.26.50.222 k8s-master
EOF
打开流量转发
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
下载docker
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum list docker-ce --showduplicates |sort -r
yum -y install docker-ce-20* docker-ce-cli-20*
systemctl enable docker && systemctl start docker
docker --version
配docker镜像加速
我这里用的道客的
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://docker.m.daocloud.io"],
"exec-opts":["native.cgroupdriver=systemd"]
}
systemctl daemon-reload
systemctl restart docker
添加阿里云yum源
配置安装k8s需要的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
yum clean all
yum makecache fast
安装kubeadm,kubelet和kubectl
yum install -y kubelet-1.21.0 kubeadm-1.21.0 kubectl-1.21.0
systemctl restart kubelet
systemctl enable kubelet
执行
docker pull coredns/coredns:1.8.0
docker tag coredns/coredns:1.8.0 registry.aliyuncs.com/google_containers/coredns/coredns:v1.8.0
主节点执行,初始化
kubeadm init --apiserver-advertise-address=192.168.121.137 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.21.0 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
主节点执行
wget https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
验证
过一小会,执行kubectl get node,显示如下,则集群安装成功
查看所有pod情况,只有当所有pod显示running才算成功
原文地址:https://blog.csdn.net/m0_68858390/article/details/140716439
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!