【参考资料】
k8s文档/安装扩展 https://kubernetes.io/docs/concepts/cluster-administration/addons/
canal安装文档 https://projectcalico.docs.tigera.io/getting-started/kubernetes/flannel/flannel
k8s安装后,启动kubelet,再运行kubeadm init 就算初始化成功了,但查看pod节点状态会发现coreDNS服务还在pending或者其他一些异常,所以接下来要去装网络控件来完善k8s
由于init启动时我们一般没有网络控件,所以会使得我们的主节点node产生污点(taint),删除污点网上很多教程
对于我们新手来说,挑哪个都无所谓,所以我就挑了个顺眼的Canal
其中若干个网络控件都需要让我们配置 controller-manager 的CIDR
第一步的tip不知道怎么用,所以就老实地按文档来
在k8s-controller-manager.yaml中配置集群CIDR
cd /etc/kubernetes/manifests/
ll
总用量 240
...
-rw------- 1 root root 2842 12月 27 17:28 kube-controller-manager.yaml
...
vim kube-controller-manager.yaml
spec:
containers:
- command:
- kube-controller-manager
- --authentication-kubeconfig=/etc/kubernetes/controller-manager.conf
- --authorization-kubeconfig=/etc/kubernetes/controller-manager.conf
- --bind-address=127.0.0.1
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --cluster-name=kubernetes
- --cluster-signing-cert-file=/etc/kubernetes/pki/ca.crt
- --cluster-signing-key-file=/etc/kubernetes/pki/ca.key
- --controllers=*,bootstrapsigner,tokencleaner
- --kubeconfig=/etc/kubernetes/controller-manager.conf
- --leader-elect=true
- --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
- --root-ca-file=/etc/kubernetes/pki/ca.crt
- --service-account-private-key-file=/etc/kubernetes/pki/sa.key
- --use-service-account-credentials=true
- --cluster-cidr=10.1.0.0/16 # 按文档加上这两条命令,这里的CIDR不要和已使用的ip地址冲突就好,我的服务器内网id是 10.0.x.x,所以使用了10.1.x.x
- --allocate-node-cidrs=true
image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.1
改好配置文件后要应用
kubectl apply -f kube-controller-manager.yaml
应用配置时感觉没生效可以先删除原来的配置
kubectl delete -f kube-controller.manager.yaml
多查看pod状态检查操作是否成功
kubectl get pods --all-namespaces
应该看到这些基本的pod在运行,多刷新几次,如果状态始终不是Running,那么检查node是不是有污点要删除
kube-system etcd-vm-20-9-centos 1/1 Running 4 29h
kube-system kube-apiserver-vm-20-9-centos 1/1 Running 4 29h
kube-system kube-controller-manager 1/1 Running 0 21h
kube-system kube-proxy-68zg7 1/1 Running 0 29h
准备好后就可以开始获取canal.yaml(curl或者wget弄到本地)
我喜欢保持自己当前目录为 /etc/kubernetes/manifests/,因为yaml文件都在这
curl https://docs.projectcalico.org/manifests/canal.yaml -O
ll
...
-rw-r--r-- 1 root root 216854 12月 27 17:43 canal.yaml
...
kubectl apply -f canal.yaml
清除一些污点后,等待pod运行起来就大功告成了,接下来就可以去弄dash_board等(组件/扩展)了
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-647d84984b-zdqwq 1/1 Running 0 22h
kube-system canal-w94hz 2/2 Running 0 22h
kube-system coredns-65c54cc984-lbxwx 1/1 Running 0 29h
kube-system coredns-65c54cc984-vw7h8 1/1 Running 0 29h
kube-system etcd-vm-20-9-centos 1/1 Running 4 29h
kube-system kube-apiserver-vm-20-9-centos 1/1 Running 4 29h
kube-system kube-controller-manager 1/1 Running 0 22h
kube-system kube-proxy-68zg7 1/1 Running 0 29h
kube-system kube-scheduler-vm-20-9-centos 1/1 Running 5 29h