中国指股网 > 聚焦 > 内容页

重新初始化k8s集群 全球微动态

2023-06-26 22:22:51 来源:博客园
执行如下命令,所有节点都执行
kubeadm reset
初始化集群,仅在master(centos01)上执行
[root@centos01 opt]# kubeadm init --apiserver-advertise-address 192.168.109.130 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.27.1 --pod-network-cidr=10.244.0.0/16.........Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:  mkdir -p $HOME/.kube  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config  sudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:  export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:  https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.109.130:6443 --token osh87v.zvo010kamsr8esmp \--discovery-token-ca-cert-hash sha256:ff4607c7c194e9f756b1eb509e64d2d926b5f8f9556a85c3c14a2d25add28230

其中,–apiserver-advertise-address:通告侦听地址–image-repository:指定镜像地址使用阿里云的,默认会使用谷歌镜像–kubernetes-version:指定当前的kubernetes的版本–pod-network-cidr=10.244.0.0/16:flannel网络的固定地址范围


(资料图片仅供参考)

仔细阅读kubeadm init执行的结果,根据提示,还需要进行3步操作

1.笔者用的是root用户,仅在master节点执行

[root@centos01 opt]# vim /etc/profile#在最后一行增加export KUBECONFIG=/etc/kubernetes/admin.conf

生效环境变量

[root@centos01 opt]# source /etc/profile

2.安装网络插件,可以选择calico或flannel,这里选择安装flannel,仅在master节点执行

下载安装文件

[root@centos01 opt]# wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

修改配置

[root@centos01 opt]# vim kube-flannel.yml#修改Network项的值,改为和--pod-network-cidr一样的值"Network": "10.244.0.0/16"#由于有时国内网络的问题,需要修改image的地址,把所有的docker.io改为dockerproxy.com#共需要修改3处,两个值image: dockerproxy.com/flannel/flannel:v0.22.0image: dockerproxy.com/flannel/flannel-cni-plugin:v1.1.2

安装网络插件

[root@centos01 opt]# kubectl apply -f kube-flannel.yml

验证安装

[root@centos01 opt]# kubectl get pods -n kube-flannelNAME                    READY   STATUS    RESTARTS       AGEkube-flannel-ds-dfngh   1/1     Running   17 (13m ago)   6d1hkube-flannel-ds-qll8g   1/1     Running   12 (13m ago)   6d1h

3.其他节点加入集群,非master节点都执行

[root@centos02 opt]# kubeadm join 192.168.109.130:6443 --token osh87v.zvo010kamsr8esmp --discovery-token-ca-cert-hash sha256:ff4607c7c194e9f756b1eb509e64d2d926b5f8f9556a85c3c14a2d25add28230
验证安装结果,仅在master节点执行
[root@centos01 opt]# kubectl get nodesNAME       STATUS   ROLES           AGE    VERSIONcentos01   Ready    control-plane   134m   v1.27.1centos02   Ready              133m   v1.27.1
[root@centos01 opt]# kubectl get pods -n kube-systemNAME                               READY   STATUS    RESTARTS   AGEcoredns-7bdc4cb885-l4vs2           1/1     Running   0          9m3scoredns-7bdc4cb885-wzc8x           1/1     Running   0          9m3setcd-centos01                      1/1     Running   0          9m18skube-apiserver-centos01            1/1     Running   0          9m18skube-controller-manager-centos01   1/1     Running   0          9m19skube-proxy-m92hr                   1/1     Running   0          28skube-proxy-pv4hw                   1/1     Running   0          9m3skube-scheduler-centos01            1/1     Running   0          9m18s

重启一遍所有服务器节点,有可能会暴露出来隐藏的问题,再次验证以上结果,仍然正常。

最后,推荐一个发布应用的平台https://gitee.com/i512team/dhorse,是一个以应用为中心的云原生DevOps系统,能够实现持续集成、持续部署、微服务治理等功能,主要特点:部署简单、操作简洁、功能快速。

上一篇 下一篇
x 广告
推荐阅读