ubuntu18.04下kubeadm安装k8s(1.18.8版本)
ubuntu18.04下kubeadm安装k8s(1.18.8版本)
此版本k8s所需docker环境安装请移步:ubuntu18.04安装指定版本docker
1.准备
关闭防火墙
sudo ufw disable
关闭交换空间
#临时关闭swap分区
sudo swapoff -a
#永久关闭swap分区
sed -ri 's/.*swap.*/#&/' /etc/fstab
2.分别在master和node上安装kubeadm,kubectl,kubelet(指定相同版本)
先编辑/etc/apt/sources.list添加如下一行
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
然后更新一下仓库
sudo apt-get update
下载指定版本k8s组件
sudo apt-get install kubeadm=1.18.8-00 kubectl=1.18.8-00 kubelet=1.18.8-00
3.编写init脚本,初始化master
kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
cgroup-driver: "systemd"
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: "v1.18.8"
clusterName: "example-cluster"
controllerManager:
extraArgs:
horizontal-pod-autoscaler-sync-period: "10s"
node-monitor-grace-period: "10s"
apiServer:
extraArgs:
runtime-config: "api/all=true"
imageRepository: "registry.cn-hangzhou.aliyuncs.com/google_containers"
最后一行指定镜像仓库,解决了国内下载不了默认仓库的问题
在master输入以下命令执行init
sudo kubeadm init --config kubeadm.yaml
初始化成功后会打印如下内容:
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
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 172.16.0.10:6443 --token k0bed6.i3g8s7xsvo67h9ew \
--discovery-token-ca-cert-hash sha256:3477817c7219dbe9538add6322afdb53154e4171e123d5b2abeb89272b843804
在master上执行以设置相关环境
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
后面其他节点要加入集群只需输入如下命令
kubeadm join 172.16.0.10:6443 --token k0bed6.i3g8s7xsvo67h9ew \
--discovery-token-ca-cert-hash sha256:3477817c7219dbe9538add6322afdb53154e4171e123d5b2abeb89272b843804
4.安装weave网络插件
sudo kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
5.在node安装kubeadm,kuebctl,kubelet步骤并且输入master init成功后的kubeadm join命令即可加入集群
6.安装rook存储插件
sudo git clone --single-branch --depth=1 --branch v1.8.2 https://github.com/rook/rook.git
kubectl apply -f ./rook/deploy/examples/common.yaml
kubectl apply -f ./rook/deploy/examples/operator.yaml
kubectl apply -f ./rook/deploy/examples/crds.yaml
kubectl apply -f ./rook/deploy/examples/cluster.yaml
问题:
1 node(s) didn't match pod affinity/anti-affinity, 1 node(s) didn't satisfy existing pods anti-affinity rules, 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
新版本rook必须裸盘初始化
解决方法:给虚拟机新添加一块硬盘
failed to perform validation before cluster creation: cannot start 3 mons on 2 node(s) when allowMultiplePerNode is false
集群不允许在每个节点部署多个实例
解决方法:把cluster.yaml中的allowMultiplePerNode改为true
查看集群状态相关命令:
查看rook相关pods状态:
kubectl get pods -n rook-ceph
查看所有pods状态:
kubectl get pods --all-namespaces
查看某个Pod详情:
kubectl describe pod -n kube-system weave-net-ncspr
查看rook创建状态:
kubectl get cephcluster -n rook-ceph rook-ceph -w
查看所有节点状态:
kubectl get nodes
查看某个node详情:
kubectl describe node k8s-node1
重置集群到init前状态:
sudo kubeadm reset
设置cgroupdriver=systemd
在/etc/docker/daemon.json添加一句
"exec-opts": ["native.cgroupdriver=systemd"]
这个在启动时报cgroupdriver warning时会用到