如何调试 kubectl apply for kube-flannel.yml?

How to debug kubectl apply for kube-flannel.yml?

我正在尝试按照以下文档创建一个 kubernetes 集群:https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

首先,我在带有 Vagrant 的 VirtualBox 中的 Coreos (1520.9.0) 上安装了带有 docker 映像的 kubeadm:

docker run -it \
    -v /etc:/rootfs/etc \
    -v /opt:/rootfs/opt \
    -v /usr/bin:/rootfs/usr/bin \
    -e K8S_VERSION=v1.8.4 \
    -e CNI_RELEASE=v0.6.0 \
    xakra/kubeadm-installer:0.4.7 coreos

这是我的 kubeadm init:

kubeadm init --pod-network-cidr=10.244.0.0/16

当运行命令时:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

它returns:

clusterrole "flannel" configured
clusterrolebinding "flannel" configured
serviceaccount "flannel" configured
configmap "kube-flannel-cfg" configured
daemonset "kube-flannel-ds" configured

但是如果我检查 "kubectl get pods --all-namespaces"

它returns:

NAMESPACE     NAME                              READY     STATUS             RESTARTS   AGE
kube-system   etcd-coreos1                      1/1       Running            0          18m
kube-system   kube-apiserver-coreos1            1/1       Running            0          18m
kube-system   kube-controller-manager-coreos1   0/1       CrashLoopBackOff   8          19m
kube-system   kube-scheduler-coreos1            1/1       Running            0          18m

使用 journalctl -f -u kubelet 我可以看到这个错误:Unable to update cni config: No networks found in /etc/cni/net.d

我怀疑命令有问题kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

有没有办法知道为什么这个命令不起作用?我可以从任何地方获取一些日志吗?

就在今晚,我使用 kubespray 在 CoreOS 上使用 flannel (vxlan) 配置了一个 vagrant 集群,我也对 flannel 如何成为 Kubernetes 中的 Pod 感到困惑

事实证明,as seen here, that they are using flannel-cni image from quay.io 使用 flannel side-car 和 hostDir volume-mounts 写出 CNI 文件;它输出 cni-conf.json(将 CNI 配置为使用 flannel),然后是 net-conf.json(配置 flannel 使用的子网和后端)。

我希望 jinja2 mustache 语法不会混淆答案,但我发现看到 Kubernetes 人员如何选择这样做非常有趣 "for real" 与示例进行比较和对比 DaemonSet 在 flannel-cni 自述文件中给出。我想这是很长的说法:尝试 flannel-cni README 中的描述符,然后如果它不起作用,看看它们是否在某些方面与已知的工作 kubespray 设置不同

update: 作为具体示例,观察 the Documentation yaml doesn't include the --iface= 开关,如果您的 Vagrant 设置同时使用 NAT 和 "private_network" 那么它可能意味着flannel 绑定到 eth0(NAT 之一),而不是 eth1 具有更静态的 IP。我看到了文档中提到的警告,但无法立即回忆起在哪里引用它

更新 2

Is there a way to know why this command doesn't work? Can I get some logs from anywhere?

人们可能几乎总是以相同的方式访问 Pod(即使是静态定义的,例如 kube-controller-manager-coreos1)的日志:kubectl --namespace=kube-system logs kube-controller-manager-coreos1,并且在 CrashLoopBackOff 情况下,添加 -p 用于“-p"revious will show the logs from the most recent crash (but only for a few seconds, not indefinitely), and occasionally kubectl --namespace=kube-system describe pod kube-controller-manager-coreos1 will show helpful information in either the Events section at the bottom, or in the "Status”块,如果它因某种原因被终止

在出现非常严重的故障的情况下,例如 apiserver 无法启动(因此 kubectl logs 不会做任何事情),然后 ssh-ing 到节点并使用 journalctl -u kubelet.service --no-pager --lines=150docker logs ${the_sha_or_name} 尝试查看任何错误文本。在后一种情况下,您几乎肯定需要 docker ps -a 来查找已退出容器的 sha 或名称,但同样的 "only for a few seconds" 也适用,因为死容器将在一段时间后被修剪。

对于 vagrant,可以通过以下几种方式之一通过 ssh 进入 VM:

  • vagrant ssh coreos1
  • vagrant ssh-config > ssh-config && ssh -F ssh-config coreos1
  • 或者如果它有一个 "private_network" 地址,例如 192.168.99.101 之类的,那么您通常可以 ssh -i ~/.vagrant.d/insecure_private_key core@192.168.99.101 但前两个几乎总是更方便