2、kubernetes的Kubeadm 部署安装

x33g5p2x  于2021-12-25 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(554)

在k8s-master01、k8s-node01、k8s-node02上执行:

kube-proxy开启ipvs的前置条件

modprobe br_netfilter

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF

chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

安装 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 update -y && yum install -y docker-ce

## 创建 /etc/docker 目录
mkdir /etc/docker

# 配置 daemon.
cat > /etc/docker/daemon.json <<EOF
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "100m"
    },
    "registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com"]
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

# 重启docker服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker

安装 Kubeadm (主从配置:k8s-master01、k8s-node01、k8s-node02)

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
yum install kubelet kubeadm kubectl -y
systemctl enable kubelet.service
systemctl start kubelet.service

初始化主节点 (k8s-master01).

部署Kubernetes Master主节点:

kubeadm init --apiserver-advertise-address=192.168.80.137 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.20.2 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16

master01节点:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# 关闭swap(k8s禁止虚拟内存以提高性能)在(k8s-master01、k8s-node01、k8s-node02)

sed -ri 's/.*swap.*/#&/' /etc/fstab #永久
reboot

在k8s-node01、k8s-node02上执行:

kubeadm join 192.168.60.10:6443 --token 51guny.dnojseiegh570hp4 \
    --discovery-token-ca-cert-hash sha256:2f99391a680837618cb8cca7c40d982e981d0fdae8a4b85a07bd8bda7dc01e84

改写/etc/hosts文件

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.60.10 k8s-master01
192.168.60.20 k8s-node01
192.168.60.21 k8s-node02

加入主节点以及其余工作节点

执行安装日志中的加入命令即可

部署网络

在k8s-master01、k8s-node01、k8s-node02上执行:

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

docker pull quay.io/coreos/flannel:v0.13.1-rc2

docker save quay.io/coreos/flannel:v0.13.1-rc2 -o flannel.tar.gz

kubectl apply -f kube-flannel.yml

相关文章