目录
一、降级缘由
在 K8s 1.24.1 下安装 Kubesphere 不成功,查看官网文档,说明如下:
如需在 Kubernetes 上安装 KubeSphere 3.3.0,您的 Kubernetes 版本必须为:v1.19.x,v1.20.x,v1.21.x,v1.22.x 或 v1.23.x(实验性支持)。
二、reset
[root@master01 kubernetes]# kubeadm reset
[reset] Reading configuration from the cluster...
[reset] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
W0701 16:51:13.483568 3296432 preflight.go:55] [reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]:
三、卸载 kubelet、kubeadm、kubectl 1.24.1
yum remove bubeadm kubectl kubelet -y
四、查看版本
yum list kubelet kubeadm kubectl --showduplicates | sort -r
...
kubelet.x86_64 1.24.2-0 kubernetes
kubelet.x86_64 1.24.1-0 kubernetes
kubelet.x86_64 1.24.0-0 kubernetes
kubelet.x86_64 1.23.8-0 kubernetes
kubelet.x86_64 1.23.7-0 kubernetes
kubelet.x86_64 1.23.6-0 kubernetes
kubelet.x86_64 1.23.5-0 kubernetes
kubelet.x86_64 1.23.4-0 kubernetes
kubelet.x86_64 1.23.3-0 kubernetes
kubelet.x86_64 1.23.2-0 kubernetes
kubelet.x86_64 1.23.1-0 kubernetes
kubelet.x86_64 1.23.0-0 kubernetes
kubelet.x86_64 1.22.9-0 kubernetes
kubelet.x86_64 1.22.8-0 kubernetes
kubelet.x86_64 1.22.7-0 kubernetes
kubelet.x86_64 1.22.6-0 kubernetes
kubelet.x86_64 1.22.5-0 kubernetes
kubelet.x86_64 1.22.4-0 kubernetes
kubelet.x86_64 1.22.3-0 kubernetes
kubelet.x86_64 1.22.2-0 kubernetes
kubelet.x86_64 1.22.11-0 kubernetes
...
五、安装 kubelet、kubeadm、kubectl 1.23.8
yum install -y kubeadm-1.23.8 kubectl-1.23.8 kubelet-1.23.8
六、初始化集群
1.配置文件
vi kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.1.28
bindPort: 6443
nodeRegistration:
criSocket: unix:///run/containerd/containerd.sock
taints:
- effect: PreferNoSchedule
key: node-role.kubernetes.io/master
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.23.8
imageRepository: registry.aliyuncs.com/google_containers
networking:
podSubnet: 10.122.0.0/16
serviceSubnet: 10.10.0.0/16
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
failSwapOn: false
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
2.初始化
kubeadm init --config kubeadm.yaml
[root@master01 kubernetes]# kubeadm init --config kubeadm.yaml
[init] Using Kubernetes version: v1.23.8
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master01] and IPs [10.10.0.1 192.168.1.28]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost master01] and IPs [192.168.1.28 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master01] and IPs [192.168.1.28 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 10.536485 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
NOTE: The "kubelet-config-1.23" naming of the kubelet ConfigMap is deprecated. Once the UnversionedKubeletConfigMap feature gate graduates to Beta the default name will become just "kubelet-config". Kubeadm upgrade will handle this transition transparently.
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node master01 as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node master01 as control-plane by adding the taints [node-role.kubernetes.io/master:PreferNoSchedule]
[bootstrap-token] Using token: lrr8m2.02zygnbccmbnfqqk
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
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/config
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You 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.1.28:6443 --token lrr8m2.02zygnbccmbnfqqk \
--discovery-token-ca-cert-hash sha256:1a6fc5da92af0e36f61c910883f12a2edfd854b943669c271187db426b210859
3.拷贝文件到默认路径
拷贝 kubectl 使用的连接 k8s 认证文件到默认路径:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
4.查看节点状态
kubectl get node
NAME STATUS ROLES AGE VERSION
master01 Ready control-plane,master 3m31s v1.23.8
5.查看 pod 状态
由于没安装 calico,coredns 状态还不正常。
kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-6d8c4cb4d-cpjh9 0/1 ContainerCreating 0 18h
coredns-6d8c4cb4d-csc8f 0/1 ContainerCreating 0 18h
etcd-master01 1/1 Running 0 18h
kube-apiserver-master01 1/1 Running 0 18h
kube-controller-manager-master01 1/1 Running 0 18h
kube-proxy-r5rtc 1/1 Running 0 18h
kube-scheduler-master01 1/1 Running 0 18h
6.安装calico网络
下载:
wget https://docs.projectcalico.org/manifests/calico.yaml
修改 Pod 网络定义:
# The default IPv4 pool to create on startup if none exists. Pod IPs will be
# chosen from this range. Changing this value after installation will have
# no effect. This should fall within `--cluster-cidr`.
- name: CALICO_IPV4POOL_CIDR
value: "10.122.0.0/16"
应用 calico.yaml 配置:
kubectl apply -f calico.yaml
查看 pod:
kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-6b77fff45-czfmp 1/1 Running 0 19s
calico-node-fsbl4 1/1 Running 0 19s
coredns-6d8c4cb4d-cpjh9 1/1 Running 0 19h
coredns-6d8c4cb4d-csc8f 1/1 Running 0 19h
etcd-master01 1/1 Running 0 19h
kube-apiserver-master01 1/1 Running 0 19h
kube-controller-manager-master01 1/1 Running 0 19h
kube-proxy-r5rtc 1/1 Running 0 19h
kube-scheduler-master01 1/1 Running 0 19h
此时状态已正常。
7.向集群添加 node 节点
kubeadm join 192.168.1.28:6443 --token lrr8m2.02zygnbccmbnfqqk \
--discovery-token-ca-cert-hash sha256:1a6fc5da92af0e36f61c910883f12a2edfd854b943669c271187db426b210859