k8s安装
2022-11-16 本文已影响0人
mafa1993
更改网络配置
vi /etc/netplan/00-installer-config.yaml
network:
ethernets:
enp0s3:
dhcp4: true
enp0s8:
dhcp4: no
addresses:
- 192.168.107.128/24
version: 2
netplan apply
Set no password for sudo
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
SSH to your virtual machine. and follow below instructure.
If you are not using Macbook, prepare a Linux OS and follow below instructure.
Install kubernetes by kubeadm
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
Installing runtime
https://docs.docker.com/engine/install/ubuntu/
Update the apt package index and install packages to allow apt to use a repository over HTTPS:
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add Docker repository
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
$ sudo apt-get update
$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io
Install kubernetes
Installing kubeadm, kubelet and kubectl
$ cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF
$ curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add
$ sudo apt-get update
$ sudo apt-get install -y kubelet=1.19.15-00 kubeadm=1.19.15-00 kubectl=1.19.15-00
$ sudo apt-mark hold kubelet kubeadm kubectl
kubeadm init
$ sudo kubeadm init \
--image-repository registry.aliyuncs.com/google_containers \
--apiserver-advertise-address=192.168.34.2
Copy kubeconfig
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
Untaint master
pod一般不会调度到master节点上,untaint以后,master节点可以是的pod调度到master节点
$ kubectl taint nodes --all node-role.kubernetes.io/master-
Join other node
$ kubeadm join 192.168.2.116:6443 --token oig5z4.hofxyadrsfwhzxa9 \
--discovery-token-ca-cert-hash sha256:98172da8c89c09a176eb9e543e7decbc3a0dedf2c1a5ed16d83d16cb04e22513
Install cilium
$ helm install cilium cilium/cilium --version 1.9.1 \
--namespace kube-system \
--set kubeProxyReplacement=strict \
--set k8sServiceHost=192.168.34.2 \
--set k8sServicePort=6443
Install calico cni plugin
https://docs.projectcalico.org/getting-started/kubernetes/quickstart
$ kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
$ kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml
$ for i in `kubectl api-resources | grep true | awk '{print \$1}'`; do echo $i;kubectl get $i -n rook-ceph; done
k8s安装遇到的问题
- 使用1.25+的时候,会报错[kubelet-check] Initial timeout of 40s passed. 原因是1.24+的时候,k8s不在依赖docker,而是使用containerd 作为运行时,应为docker是个中间层,最终还是调用containerd 1.25 k8s安装
- 安装旧版k8s,ubuntu需要先加k8s源,然后apt cache查看k8s版本,进行旧版安装