ubuntu kubeadm 搭建kubernetes1.15.9
准备
-
update && 安装docker
apt-get update apt install docker
-
修改daemon.json
cat /etc/docker/daemon.json { "exec-opts":["native.cgroupdriver=systemd"], # kubelet 的 文件驱动默认cgroupfs "registry-mirrors": ["http://hub-mirror.c.163.com"] }
-
启动docker
systemctl start docker && systemctl enable docker
-
关闭swap
swapoff -a
启动k8s
-
安装kuebadm kubectl kubelet
apt install -y kubeadm=1.15.9-00 kubectl=1.15.9-00 kubelet=1.15.9-00
-
k8s 准备工作
cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf [Service] Environment="KUBELET_KUBECONFIG_ARGS=--cgroup-driver=systemd --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf" Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml" EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env EnvironmentFile=-/etc/default/kubelet ExecStart= ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS systemctl start kubelet && systemctl enable kubelet
-
初始化安装k8s
kubeadm init --kubernetes-version 1.15.9 --pod-network-cidr 10.244.0.0/16 --apiserver-advertise-address 192.168.1.94 --image-repository registry.aliyuncs.com/google_containers # 到这步有看到kubeadm join 就算是成功了
-
移动kube conf 文件
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
配置网络
kubectl get node
# 你会发现master节点属于not ready 状态
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
# raw.githubusercontent.com 访问不了的话 ,可以进入 https://gitee.com/jinmingzhi/ankr-learn/tree/master/kubernetes/flanel 这里有
# 等一会再kubectl get node 就好了
节点添加
再kubeadm init 成功后 会有
kubeadm join 命令,每个节点添加一下这个命令即可。这个命令有时效性,失效后需要重新生成hash
其他问题
问题一(coredns)
pods coredns : network: failed to find plugin "bridge" in path
[/opt/cni/bin]]
解决:
go get github.com/containernetworking/plugins
cd $GOPATH/src/github.com/containernetworking/plugins
./build_linux.sh
rm -rf /opt/cni/bin/*
cp bin/* /opt/cni/bin # 请在每一个节点上都要有噢(其他节点请使用scp命令)
问题二(其他节点无法使用kubectl的原因)
其他节点使用k8s命令时:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
解决:
将master节点的conf 文件传给其他节点即可
scp <master-user>@<master-ip>:/etc/kubernetes/admin.conf ~/.kube/conf
问题三(master 不能部署pod)
不允许运行在master 节点上部署
default-scheduler 0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate
解决:
kubectl taint nodes --all node-role.kubernetes.io/master-