介紹下系統信息;
•架構:鯤鵬 920(Kunpeng920)•OS:openEuler 20.03 (LTS-SP1)•CPU:4c•內存:16G•硬碟:若干
整個過程雖然參考了鯤鵬論壇的帖子[1],不過還是頗費周折。
TL;DR整個過程中要注意 arm64 平臺上安裝 Kubernetes 及網絡組件,需要使用 arm64 版本的鏡像。
環境配置1.關閉 selinux#臨時關閉setenforce 0#永久關閉 SELINUX=disabledvim /etc/sysconfig/selinux2. 關閉swap分區#臨時關閉swapoff -a#永久關閉 注釋 swap 行vim /etc/fstab3. 關閉防火牆systemctl stop firewalldssystemctl disable firewalld4. 網絡配置對iptables內部的nf-call需要打開的內生的橋接功能
vim /etc/sysctl.d/k8s.conf修改如下內容:
net.bridge.bridge-nf-call-iptables=1net.bridge.bridge-nf-call-ip6tables=1net.ipv4.ip_forward=1vm_swappiness=0修改完成後執行:
modprobe br_netfiltersysctl -p /etc/sysctl.d/k8s.conf5. 添加 Kubernetes 源在文件 /etc/yum.repos.d/openEuler.repo 中追加如下內容:
[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-aarch64/enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg安裝配置 iSula修改 iSula 配置,打開文件 /etc/isulad/daemon.json,按照下面的部分:
{ "registry-mirrors": [ "docker.io" ], "insecure-registries": [ "rnd-dockerhub.huawei.com" ], "pod-sandbox-image": "k8s.gcr.io/pause:3.2", // 按照對應 Kubernetes 版本進行修改,後面會有說明 "network-plugin": "cni", "cni-bin-dir": "", "cni-conf-dir": "", "hosts": [ "unix:///var/run/isulad.sock" ]}修改之後重啟 isulad
systemctl restart isuladsystemctl enable isuladKubernetes 部署1. 安裝 kubelet、kubeadm、kubectlyum install -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.02. 準備鏡像由於某種未知的網絡問題,會導致拉取 k8s.gcr.io 的鏡像失敗。需要提前下載好。
通過 kubeadm config images list --kubernetes-version 1.20.0 命令,獲取初始化所需的鏡像。這裡需要注意通過 --kubernetes-version 參數指定版本號,否則 kubeadm 是列印出最高的 1.20.x 版本的初始化鏡像(比如,1.20.x 的最高版本是 1.20.4)。
k8s.gcr.io/kube-apiserver:v1.20.0k8s.gcr.io/kube-controller-manager:v1.20.0k8s.gcr.io/kube-scheduler:v1.20.0k8s.gcr.io/kube-proxy:v1.20.0k8s.gcr.io/pause:3.2k8s.gcr.io/etcd:3.4.13-0k8s.gcr.io/coredns:1.7.對應的 arm64 版本鏡像為:
k8s.gcr.io/kube-apiserver-arm64:v1.20.0k8s.gcr.io/kube-controller-manager-arm64:v1.20.0k8s.gcr.io/kube-scheduler-arm64:v1.20.0k8s.gcr.io/kube-proxy-arm64:v1.20.0k8s.gcr.io/pause-arm64:3.2k8s.gcr.io/etcd-arm64:3.4.2-0 #支持 arm64 的 3.4.x 的最高版本k8s.gcr.io/coredns:1.7.0 #無需特別的 arm64 版本憑「運氣」下載好鏡像後,再通過 isula tag 命令修改成我們需要的:
isula tag k8s.gcr.io/kube-apiserver-arm64:v1.20.0 k8s.gcr.io/kube-apiserver:v1.20.0isula tag k8s.gcr.io/kube-controller-manager-arm64:v1.20.0 k8s.gcr.io/kube-controller-manager:v1.20.0isula tag k8s.gcr.io/kube-scheduler-arm64:v1.20.0 k8s.gcr.io/kube-scheduler:v1.20.0isula tag k8s.gcr.io/kube-proxy-arm64:v1.20.0 k8s.gcr.io/kube-proxy:v1.20.0isula tag k8s.gcr.io/pause-arm64:3.2 k8s.gcr.io/pause:3.2isula tag k8s.gcr.io/etcd-arm64:3.4.2-0 k8s.gcr.io/etcd:3.4.13-0isula tag k8s.gcr.io/coredns:1.7.0 k8s.gcr.io/coredns:1.7.03. 初始化 master 節點注意需要指定 --cri-socket 參數使用 isulad 的 API。
kubeadm init --kubernetes-version v1.20.0 --cri-socket=/var/run/isulad.sock --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 12.0.0.9:6443 --token 0110xl.lqzlegbduz2qkdhr \ --discovery-token-ca-cert-hash sha256:42b13f5924a01128aac0d6e7b2487af990bc82701f233c8a6a4790187ea064af4. 配置集群環境然後根據上面的輸出進行配置
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configexport KUBECONFIG=/etc/kubernetes/admin.conf5. 向集群添加 Node 節點重複前面的步驟:環境配置、安裝配置 iSula 以及 Kubernetes 部署 的 1 和 2。
同樣使用上面輸出的命令,再加上 --cri-socket 參數:
kubeadm join 12.0.0.9:6443 --token 0110xl.lqzlegbduz2qkdhr \ --discovery-token-ca-cert-hash \ --cri-socket=/var/run/isulad.sock配置網絡插件完成 master 節點初始化並配置完集群環境後就可以執行 kubectl 的命令了。
kubectl get nodesNAME STATUS ROLES AGE VERSIONhost-12-0-0-9 NotReady control-plane,master 178m v1.20.0看下節點,發現節點是 NotReady 的狀態,這是因為網絡插件還沒安裝。如果此時通過命令 journalctl -uf kubelet 查看 kubelet 的日誌,會看到日誌提示網絡插件沒有 ready。
kubelet.go:2160] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:iSulad: network plugin is not ready: cni config uninitialized還記得 isulad 的配置麼?
"network-plugin": "cni","cni-bin-dir": "", //使用默認 /opt/cni/bin"cni-conf-dir": "", //使用默認 /etc/cni/net.d實際上兩個目錄都是空的內容,如果目錄不存在,先創建:
mkdir -p /opt/cni/binmkdir -p /etc/cni/net.d這裡使用 calico 做為網絡插件,先下載 manifest。
wget https://docs.projectcalico.org/v3.14/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml因為是 arm64 的硬體,同樣需要使用對應 arm64 版本的鏡像,先查看要用哪些鏡像:
grep 'image:' calico.yaml | uniq image: calico/cni:v3.14.2 image: calico/pod2daemon-flexvol:v3.14.2 image: calico/node:v3.14.2 image: calico/kube-controllers:v3.14.2對應的 arm64 版本,操作步驟參考上面,不再贅述。
calico/cni:v3.14.2-arm64calico/pod2daemon-flexvol:v3.14.2-arm64calico/node:v3.14.2-arm64calico/kube-controllers:v3.14.2-arm64搞定鏡像之後執行:
kubectl apply -f calico.yaml之後就可以看到節點變成了 Ready 狀態。
測試通常都是用 nginx 的鏡像創建 pod 進行測試,但是 nginx 並沒有 arm64 的版本,這裡就用 docker 官方提供的 hello-world 鏡像。沒錯,支持 arm64。
注意:容器裡的進程列印出信息就會退出了,因此 pod 會不停的重啟,但用來測試是足夠的。
kubectl run hello-world --image hello-world:latestkubectl logs hello-world --previous可以看到
Hello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (arm64v8) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/總結至此,我們就完成了在鯤鵬平臺上基於 openEuler + iSula 部署 Kubernetes 的工作。
引用連結[1] 鯤鵬論壇的帖子: https://bbs.huaweicloud.com/forum/thread-94271-1-1.html