Creating a single master cluster with kubeadm
Creating a single master cluster with kubeadm本文涉及的内容:搭建k8s单节点集群k8s网络插件flannel的使用重启集群后,网络插件无法工作的问题及解决k8s dns测试kubeadm搭建single node k8s的过程和用kubeadm搭建多节点的方法一样,但是k8s限制在master节点上部署容器,需要取消master节点的t...
Creating a single master cluster with kubeadm
本文涉及的内容:
- 搭建k8s单节点集群
- k8s网络插件flannel的使用
- 重启集群后,网络插件无法工作的问题及解决
- k8s dns测试
kubeadm搭建single node k8s的过程和用kubeadm搭建多节点的方法一样,但是k8s限制在master节点上部署容器,需要取消master节点的taints。
kubeadm搭建双节k8s的详细过程,见kubeadm安装k8s
-
环境:
华为云ECS,规格/镜像:2vCPUs | 4GB | s3.large.2
Ubuntu 18.04 server 64bit
kubeadm1.13,flannel插件 -
搭建过程
0. 这里所有的软件已经安装完成,相关软件的安装方法及过程,见kubeadm安装k8s
-
使用fannel网络插件前的工作,pass bridged IPv4 traffic to iptables’ chains:
sysctl net.bridge.bridge-nf-call-iptables=1
-
初始化master节点
kubeadm init --pod-network-cidr=10.244.0.0/16
此时,如果正常,节点状态将是NotReady。
-
安装网络插件flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
稍等片刻,节点状态变为Ready,但是此时,创建pod并不会成功,describe 未成功创建的pod,会发现报错:1 node(s) had taints that the pod didn’t tolerate。
-
取消master的taint,即可成功创建pod
kubectl taint nodes --all node-role.kubernetes.io/master-
-
集群状态检查,因为后续搭建的系统需要域名解析,所以一定要检查dns的pod的状态
root@hw1:~# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-86c58d9df4-4wfcv 1/1 Running 0 9h coredns-86c58d9df4-nfsjh 1/1 Running 0 9h etcd-hw1 1/1 Running 0 9h kube-apiserver-hw1 1/1 Running 0 9h kube-controller-manager-hw1 1/1 Running 0 9h kube-flannel-ds-amd64-dksp8 1/1 Running 0 9h kube-proxy-h7mh4 1/1 Running 0 9h kube-scheduler-hw1 1/1 Running 0 9h root@hw1:~#
-
后续工作
a) 测试集群dns,使用busybox:1.28解析域名:apiVersion: v1 kind: Pod metadata: name: busybox namespace: default spec: containers: - image: busybox:1.28 command: - sleep - "3600" imagePullPolicy: IfNotPresent name: busybox restartPolicy: Always
root@hw1:~/k8s# kubectl create -f busybox.yaml root@hw1:~/k8s# kubectl get pods NAME READY STATUS RESTARTS AGE busybox 1/1 Running 9 9h root@hw1:~/k8s# kubectl exec busybox -- nslookup kubernetes Server: 10.96.0.10 Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local Name: kubernetes Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local root@hw1:~/k8s# kubectl exec busybox -- nslookup baidu.com Server: 10.96.0.10 Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local Name: baidu.com Address 1: 220.181.57.216 Address 2: 123.125.114.144 root@hw1:~/k8s#
搭建k8s环境遇到的问题及解决办法:
-
single node环境下,master node创建pod失败,报错:1 node(s) had taints that the pod didn’t tolerate.
原因:k8s出于安全考虑,默认master上不运行创建pod。
若要更改该限制,只需取消master的taint(污点) :kubectl taint nodes --all node-role.kubernetes.io/master-
相关内容参考:
-
kubeadm reset之后再次init,发现网络插件不可用了,查看dns pod的事件信息,报错:Failed to setup network for pod \ using network plugins “cni”: no IP addresses available in network: podnet; Skipping pod
原因:之前的集群遗留的数据造成的。
解决办法,删除docker和kubeadm的数据、删除对应的网络设备等,再重启docker,重新初始化集群:kubeadm reset systemctl stop kubelet systemctl stop docker rm -rf /var/lib/cni/ rm -rf /var/lib/kubelet/* rm -rf /etc/cni/ ifconfig cni0 down ifconfig flannel.1 down ifconfig docker0 down ip link delete cni0 ip link delete flannel.1 systemcl start docker
- 参考
更多推荐
所有评论(0)