kubernetes集群部署 本教程基于Archlinux,其他发行版大体步骤类似 容器引擎基于CRI-O
1.安装必要的组件 1 2 3 4 pacman -S kubeadm kubelet kubectl cri-o
2.启动容器引擎 1 sudo systemctl start crio
3.初始化集群 1 2 3 4 5 sudo kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.254.0.0/16 --service-cidr=10.253.0.0/16 --cri-socket=/var/run/crio/crio.sock
4.创建集群成功 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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.250:6443 --token 6xfvp5.9gdoo9c9xp87cn4c \ --discovery-token-ca-cert-hash sha256:cd43db87da74dbcb3fb4eedf4bfdb454a175431928f8accbac331a357797e104
5.安装网络插件 参考https://kubernetes.io/zh-cn/docs/concepts/cluster-administration/addons/#networking-and-network-policy
1 2 3 4 wget https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml kubectl apply -f ./kube-flannel.yml
常见问题 1.镜像拉取失败 对于containerd容器引擎,可能换源没有用,需要手动拉取pause镜像,然后手动将镜像改名
1 2 crictl pull registry.aliyuncs.com/google_containers/pause:3.9 crictl tag ${IMAGE_ID} registry.k8s.io/pause.io
修改成功后重新创建集群即可成功
2.apiserver以及etcd重启问题 对于systemd启动的linux系统,我们需要将容器引擎的资源分配策略改为systemd containerd
1 2 3 4 5 6 7 8 9 10 11 12 [plugins."io.containerd.grpc.v1.cri" .containerd.runtimes.runc.options] BinaryName = "" CriuImagePath = "" CriuPath = "" CriuWorkPath = "" IoGid = 0 IoUid = 0 NoNewKeyring = false NoPivotRoot = false Root = "" ShimCgroup = "" SystemdCgroup = true
3.网络问题 对于crio容器引擎可能需要指定网络插件配置文件的目录
1 2 3 4 5 6 7 [crio.network] plugin_dirs = [ "/opt/cni/bin" , ] systemctl restart crio kubelet