k8s搭建
===============1.修改虚拟机ip=========================vi /etc/sysconfig/network-scripts/ifcfg-ens33service network restart==================2.一键安装docker=====================yum -y updatesudo yum remove -y
===============1.修改虚拟机ip=========================
vi /etc/sysconfig/network-scripts/ifcfg-ens33
service network restart
==================2.一键安装docker=====================
yum -y update
sudo yum remove -y docker*
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install -y docker-ce-3:19.03.9-3.el7.x86_64
systemctl start docker && systemctl enable docker
docker version
cd /etc/docker
touch daemon.json
vi daemon.json
========================
{
"registry-mirrors": ["https://r6p5suuv.mirror.aliyuncs.com"]
}
=======================
systemctl daemon-reload
systemctl restart docker
================3.k8s基础环境配置==================
1、关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
2、关闭 selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久关闭
setenforce 0 # 临时关闭
3、关闭 swap
swapoff -a # 临时关闭
vim /etc/fstab # 永久关闭
#注释掉swap这行
# /dev/mapper/centos-swap swap swap defaults 0 0
systemctl reboot #重启生效
free -m #查看下swap交换区是否都为0,如果都为0则swap关闭成功
4、给三台机器分别设置主机名
hostnamectl set-hostname <hostname>
第一台:k8s-master
第二台:k8s-node1
第三台:k8s-node2
5、在 k8s-master机器添加hosts,执行如下命令,ip需要修改成你自己机器的ip
cat >> /etc/hosts << EOF
192.168.25.111 k8s-master
192.168.25.112 k8s-node1
192.168.25.113 k8s-node2
EOF
6、将桥接的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 # 生效
7、设置时间同步
yum install ntpdate -y
ntpdate time.windows.com
8、添加k8s 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
9、如果之前安装过k8s,先卸载旧版本
yum remove -y kubelet kubeadm kubectl
10、查看可以安装的版本
yum list kubelet --showduplicates | sort -r
11、安装kubelet、kubeadm、kubectl 指定版本,我们使用kubeadm方式安装k8s集群
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
12、开机启动kubelet
systemctl enable kubelet
systemctl start kubelet
==================4 初始化主节点===================
注意这里要等待4-5分钟,不要终止掉
kubeadm init --apiserver-advertise-address=192.168.25.111 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.18.0 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16
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 pod -n kube-system查看 coredns状态
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
把从节点加入到主节点
kubeadm join 172.24.80.46:6443 --token eqvieq.3uobxsu1gc9iq3nr --discovery-token-ca-cert-hash sha256:24ecb2060ca471e7fe3c39787055046c8db85e3795f3537492782a0d3808ad58
注意这里面的pod要全部为Running(大概要等6分钟)
kubectl get pod -n kube-system
没有变成Rready千万不要慌,大概要等6分钟左右才会变化
kubectl get nodes
在从节点执行,大概等个8分钟左右全部会变成Ready,千万不要手动终止掉
kubeadm join 192.168.25.111:6443 --token e49rz2.4al5ffyq13fovb9k \
--discovery-token-ca-cert-hash sha256:ad47d384a32830782c02f8a4c2ab880243835b5a76815b192ba99ad847bdfd10
====================
更多推荐
所有评论(0)