这是安装包的下载地址
链接:https://pan.baidu.com/s/1O6qkENrmoeLLTkgMHdMISw?pwd=sfez
提取码:sfez

下载后,解压到服务器,进入到 目录 src/conf,配置master 和node节点的ip信息
然后进入解压后的目录src ,执行以下命令,这个命令有变量要改的,需要注意

sh install-kube.sh -mode offline -v v1.25.3 -addr ${ip} -p ${port} -tk tarzan.e6fa0b76a6898af7 --flannel

注意,这里的 ${ip} ${port} 是变量,master 的ip port对应的是6443

接下来安装,遇到询问y/n 全部y

[root@localhost src]# kubectl get pods -A
NAMESPACE      NAME                                 READY   STATUS     RESTARTS   AGE
kube-flannel   kube-flannel-ds-vlfzw                0/1     Init:1/2   0          26s
kube-system    coredns-7f8cbcb969-44ctw             0/1     Pending    0          40s
kube-system    coredns-7f8cbcb969-sb6gr             0/1     Pending    0          40s
kube-system    etcd-k8s-master                      1/1     Running    0          53s
kube-system    kube-apiserver-k8s-master            1/1     Running    0          53s
kube-system    kube-controller-manager-k8s-master   1/1     Running    0          55s
kube-system    kube-proxy-mbqtk                     1/1     Running    0          40s
kube-system    kube-scheduler-k8s-master            1/1     Running    0          53s

如果遇到flannel安装失败,执行以下命令

    docker load -i offline/images/kube-flannel-v0.24.0.tar.gz
    kubectl apply -f addons/kube-flannel/0.24.0/flannel-init.yaml
    kubectl get all -n kube-flannel
    check_pod_status kube-flannel

删除掉挂载的pod或者等几分钟,即可

[root@localhost src]# kubectl get pods -A
NAMESPACE      NAME                                 READY   STATUS    RESTARTS   AGE
kube-flannel   kube-flannel-ds-vlfzw                1/1     Running   0          6m36s
kube-system    coredns-7f8cbcb969-pztk5             1/1     Running   0          5m41s
kube-system    coredns-7f8cbcb969-sb6gr             1/1     Running   0          6m50s
kube-system    etcd-k8s-master                      1/1     Running   0          7m3s
kube-system    kube-apiserver-k8s-master            1/1     Running   0          7m3s
kube-system    kube-controller-manager-k8s-master   1/1     Running   0          7m5s
kube-system    kube-proxy-mbqtk                     1/1     Running   0          6m50s
kube-system    kube-scheduler-k8s-master            1/1     Running   0          7m3s

成功后,我们再来看下来当前的src目录,生成了一个目录kube_slave.tar.gz

[root@localhost src]# ls
addons            conf       install-addons.sh  install.log        kube_slave         offline          setupconfig.sh
clean-residue.sh  docker.sh  install-kube.sh    kubeadm-init.yaml  kube_slave.tar.gz  rpm-packages.sh  update-repos.sh
[root@localhost src]# 

把这个目录kube_slave.tar.gz上传到node节点的服务器,解压,在node节点执行以下命令

sh install-kube.sh -mode offline -v v1.25.3 -addr ${ip} -p 6443 -tk tarzan.e6fa0b76a6898af7

${ip} -p ${port} 变量的ip改为node节点的ip,port为6443

把master 的/etc/kubernetes/admin.conf 复制到node节点

scp admin.conf root@192.168.0.90:/etc/kubernetes/

然后再执行下面命令
上面的命令在node节点执行完后,再次执行node的环境变量命令

        mkdir -p $HOME/.kube
        mv $HOME/.kube/config $HOME/.kube/config.bak
        kube_admin_config_file="/etc/kubernetes/admin.conf"
        sudo cp -i $kube_admin_config_file $HOME/.kube/config
        sudo chown $(id -u):$(id -g) $HOME/.kube/config
        [[ -z $(grep $kube_admin_config_file ~/.bashrc) ]] && echo "export KUBECONFIG=$kube_admin_config_file" >> $HOME/.bashrc

然后重启kubelet

等几分钟,即可

如果还是遇到flannel下载安装失败,,在node节点也会遇到该问题的,可以执行下面命令

ctr images pull docker.io/kamalyes/kube-flannel:v0.24.0

node节点加入master节点命令如下,在master先执行命令:

kubeadm token create --print-join-command --ttl=0


[root@localhost src]# kubeadm token create --print-join-command --ttl=0
kubeadm join 192.168.0.80:6443 --token fgj80u.4xnh88twpcme1nvb --discovery-token-ca-cert-hash sha256:9ff427c4d1413109a2aeee3a11d027807f76e46c5ff59f0fefaa0913ef1e895f 
[root@localhost src]# 

然后把生成后的命令拿到node节点去执行

目前基本上已完成k8s集群的安装

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐