These days I created a K8s 1.21.0 cluster on Ubuntu 18.04 to prepare the CKA exam, and found there are some tips which could be shared here.
To make it simple, the cluster is based on CRI-O container runtime and another reason is that CRI-O is also used by RedHat Openshift 4 and I also want to know more about it.
First of first, need to upgrade the kernel to 5.X:
sudo apt-get install --install-recommends linux-generic-hwe-18.04
Almost no one mentioned this point and it took me more than one hour to figure out I had to upgrade the kernel to 5.X to support overlay2 or the container could not be created successfully and the kubeadm would always failed.
Then refer to this page: Install cri-o runtime
OS=xUbuntu_18.04 VERSION=1.21 cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ / EOF cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ / EOF curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add - curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers-cri-o.gpg add - sudo apt-get update sudo apt-get install cri-o cri-o-runc sudo systemctl daemon-reload sudo systemctl enable crio --now
Then continue to install kubeadm, kubectl and kubelet.
sudo apt-get install -y apt-transport-https ca-certificates curl sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubelet=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00 sudo apt-mark hold kubelet kubeadm kubectl
Make sure the /etc/hosts files are consistent on all nodes and disable swap.
And below code was used to make sure the kubeadm would use systemd:
# kubeadm-config.yaml kind: ClusterConfiguration apiVersion: kubeadm.k8s.io/v1beta3 kubernetesVersion: v1.21.0 --- kind: KubeletConfiguration apiVersion: kubelet.config.k8s.io/v1beta1 cgroupDriver: systemd serverTLSBootstrap: true
Then run 'kubeadm init --config kubeadm-config.yaml' as instructed in the Kubernetes document and you will get below error message:
neilzh@k8smaster:~$ sudo kubeadm init --config ./kubeadm-config.yaml W0806 09:25:36.251646 10406 strict.go:47] unknown configuration schema.GroupVersionKind{Group:"kubeadm.k8s.io", Version:"v1beta3", Kind:"ClusterConfiguration"} for scheme definitions in "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme/scheme.go:31" and "k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs/scheme.go:28" no kind "ClusterConfiguration" is registered for version "kubeadm.k8s.io/v1beta3" in scheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme/scheme.go:31" To see the stack trace of this error execute with --v=5 or higher
I searched the error and could not find any answer so I tried to modify the file many times and finally below modification fixed it.
apiVersion: kubeadm.k8s.io/v1beta3 --> apiVersion: kubeadm.k8s.io/v1beta2
Then the cluster could be created.