clusterrole.rbac.authorization.k8s.io/calico created clusterrole.rbac.authorization.k8s.io/flannel created clusterrolebinding.rbac.authorization.k8s.io/canal-flannel created clusterrolebinding.rbac.authorization.k8s.io/canal-calico created
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/canal/canal.yaml
输出
configmap/canal-config created daemonset.extensions/canal created serviceaccount/canal created customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org created customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org created
运行以下查看启动的 Pod
kubectl get pods --all-namespaces
输出为
NAMESPACE NAME READY STATUS RESTARTS AGE kube-system canal-rj2fm 0/3 ContainerCreating 0 44s kube-system coredns-bccdc95cf-rgtbx 0/1 Pending 0 11m kube-system coredns-bccdc95cf-x6j8l 0/1 Pending 0 11m kube-system etcd-k8s-node1 1/1 Running 0 11m kube-system kube-apiserver-k8s-node1 1/1 Running 0 10m kube-system kube-controller-manager-k8s-node1 1/1 Running 0 10m kube-system kube-proxy-zcssq 1/1 Running 0 11m kube-system kube-scheduler-k8s-node1 1/1 Running 0 10m
可以看出 canal 正在创建容器, 而 coredns 处于 pending 状态。 由于需要下载 canal 镜像,所以需要一些时间,等镜像下载完成后,则 coredns 的状态变温 Running 。
需要注意的是,如果出现 ErrImagePull 等错误,则可能是由于 canal 镜像由于在 google 服务器访问不到的缘故,此时需要开启 VPN 才能正常下载。
等镜像下载完成后,再次运行 kubectl get pods --all-namespaces , 则状态都正常了,如下所示:
NAMESPACE NAME READY STATUS RESTARTS AGE kube-system canal-rj2fm 3/3 Running 0 35m kube-system coredns-bccdc95cf-rgtbx 1/1 Running 0 46m kube-system coredns-bccdc95cf-x6j8l 1/1 Running 0 46m kube-system etcd-k8s-node1 1/1 Running 1 46m kube-system kube-apiserver-k8s-node1 1/1 Running 1 45m kube-system kube-controller-manager-k8s-node1 1/1 Running 1 45m kube-system kube-proxy-zcssq 1/1 Running 1 46m kube-system kube-scheduler-k8s-node1 1/1 Running 1 45m
此时再运行 kubectl get node 查看 master 节点的状态,则状态已经 Ready, 如下
NAME STATUS ROLES AGE VERSION k8s-node1 Ready master 48m v1.15.0
部署 Worker 节点首先在 master 节点上执行以下命令来获取在集群中添加节点的命令
kubeadm token create --print-join-command
输出为
kubeadm join 192.168.56.11:6443 --token eb0k80.qhqbjon1mh55w803 --discovery-token-ca-cert-hash sha256:ca524d88dbcc9a79c70c4cf21fba7252c0f12e5ab0fe9674e7f6998ab9fb5901
然后在每个 worker 节点上执行上面的命令,这个时候 kubernetes 会使用 DaemonSet 在所有节点上都部署 canal 和 kube-proxy。
需要注意的是,如果出现 ErrImagePull 等错误,则可能是由于镜像由于在 google 服务器访问不到的缘故,此时需要开启 VPN 才能正常下载。
等待全部部署完毕,在 master 节点运行以下命令查看信息。
查看所有 daemonset
kubectl get daemonset --all-namespaces