Create Kubernetes 1.21.0 on Ubuntu 18.04

NeilZhang
NeilZhang
管理员
140
文章
106.8千
浏览
Kubernetes评论1,358字数 546阅读1分49秒阅读模式

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt-get install --install-recommends linux-generic-hwe-18.04
sudo apt-get install --install-recommends linux-generic-hwe-18.04
  1. 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
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
  1. OS=xUbuntu_18.04
  2. VERSION=1.21
  3. cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
  4. deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /
  5. EOF
  6. cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list
  7. deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /
  8. EOF
  9.  
  10. 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 -
  11. 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 -
  12.  
  13. sudo apt-get update
  14. sudo apt-get install cri-o cri-o-runc
  15. sudo systemctl daemon-reload
  16. sudo systemctl enable crio --now

Then continue to install kubeadm, kubectl and kubelet.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
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
  1. sudo apt-get install -y apt-transport-https ca-certificates curl
  2. sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
  3. 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
  4. sudo apt-get update
  5. sudo apt-get install -y kubelet=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00
  6. 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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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
# 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
  1. # kubeadm-config.yaml
  2. kind: ClusterConfiguration
  3. apiVersion: kubeadm.k8s.io/v1beta3
  4. kubernetesVersion: v1.21.0
  5. ---
  6. kind: KubeletConfiguration
  7. apiVersion: kubelet.config.k8s.io/v1beta1
  8. cgroupDriver: systemd
  9. serverTLSBootstrap: true

Then run 'kubeadm init --config kubeadm-config.yaml' as instructed in the Kubernetes document and you will get below error message:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
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
  1. neilzh@k8smaster:~$ sudo kubeadm init --config ./kubeadm-config.yaml
  2. 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"
  3. 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"
  4. 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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apiVersion: kubeadm.k8s.io/v1beta3 --> apiVersion: kubeadm.k8s.io/v1beta2
apiVersion: kubeadm.k8s.io/v1beta3 --> apiVersion: kubeadm.k8s.io/v1beta2
  1. apiVersion: kubeadm.k8s.io/v1beta3 --> apiVersion: kubeadm.k8s.io/v1beta2

Then the cluster could be created.

 最后更新:2021-12-29
  • 本文由 NeilZhang 发表于07/08/2021 04:57:49
  • Repost please keep this link: https://www.dbcloudsvc.com/blogs/kubernetes/create-kubernetes-1-21-0-on-ubuntu-18-04/
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定