机器配置
ip | 配置 | 操作系统 |
---|---|---|
10.101.139.129 | 2c 4g | centos7.8 |
10.101.139.130 | 1c 2g | centos7.8 |
10.101.139.131 | 1c 2g | centos7.8 |
预配置
配置机器名
hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2
修改etc/hosts
cat > /etc/hosts << EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.139.129 master
192.168.139.130 node1
192.168.139.131 node2
EOF
sysctl --system
关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
安装时间服务器以及同步
yum install ntpdate -y
ntpdate time.windows.com
配置go环境
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go代理地址设置
go env -w GOPROXY=https://goproxy.cn,https://gocenter.io,https://goproxy.io,direct
etcd安装
git clone -b v3.5.0 https://hub.fastgit.org/etcd-io/etcd.git
cd etcd
./build.sh
export PATH="$PATH:`pwd`/bin"
安装docker
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-18.06.1.ce-3.el7
docker配置
配置docker hub,
修改docker的cgroup驱动为systemd,和k8s cgroup驱动保持一致
sudo tee /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com"],
"exec-opts":["native.cgroupdriver=systemd"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl enable docker.service
允许容器读取主机文件系统
vi /etc/sysconfig/selinux
SELINUX=disabled
关闭共享分区
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
kubeadm安装
yum源配置
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
安装 kubelet kubectl kubeadm
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
启动kubelet
systemctl start kubelet
systemctl enable kubelet
启动Master/增加节点
kubeadm init \
--apiserver-advertise-address=10.101.139.129 \
--image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
--kubernetes-version 1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
启动集群
增加网络
master 节点执行
wget https://docs.projectcalico.org/manifests/calico.yaml
kubectl apply -f calico.yaml
有疑问加站长微信联系(非本文作者)