当我尝试遵循Kubernetes Configure Multiple Schedulers guide时,无法成功运行my-scheduler pod。

我成功构建了镜像并将其推送到注册表,该镜像显示在我的docker和Google Could Platform中。
但是,当我应用部署文件设置Pod时,状态为CrashLoopBackOff

my-scheduler-64576b7897-8b549            0/1     CrashLoopBackOff   14         84m

这是kuberctl describe pod my-scheduler-64576b7897-8b549 -n kube-system的输出:

Name:               my-scheduler-64576b7897-8b549
Namespace:          kube-system
Priority:           0
PriorityClassName:  <none>
Node:               minikube/10.0.2.15
Start Time:         Tue, 07 May 2019 15:06:59 -0500
Labels:             component=scheduler
                    pod-template-hash=64576b7897
                    tier=control-plane
                    version=second
Annotations:        <none>
Status:             Running
IP:                 172.17.0.15
Controlled By:      ReplicaSet/my-scheduler-64576b7897
Containers:
  kube-second-scheduler:
    Container ID:  docker://a0cadf03dd5ffd11cbb6f1f8e669fc04cd6aa00aa6f361550f06f32785a4d63c
    Image:         gcr.io/my-gcp-project-239900/my-kube-scheduler:1.0
    Image ID:      docker-pullable://gcr.io/my-gcp-project-239900/my-kube-scheduler@sha256:0895687b7646d159438f086e8f8b23b253332930e169cf29d8b9951ebf3ba653
    Port:          <none>
    Host Port:     <none>
    Command:
      /usr/local/bin/kube-scheduler
      --address=1.1.1.1
      --leader-elect=false
      --scheduler-name=my-scheduler
    State:          Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Tue, 07 May 2019 15:07:45 -0500
      Finished:     Tue, 07 May 2019 15:07:45 -0500
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Tue, 07 May 2019 15:07:24 -0500
      Finished:     Tue, 07 May 2019 15:07:24 -0500
    Ready:          False
    Restart Count:  3
    Requests:
      cpu:        100m
    Liveness:     http-get http://:10251/healthz delay=15s timeout=1s period=10s #success=1 #failure=3
    Readiness:    http-get http://:10251/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from my-scheduler-token-lzwvk (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  my-scheduler-token-lzwvk:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  my-scheduler-token-lzwvk
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age               From               Message
  ----     ------     ----              ----               -------
  Normal   Scheduled  48s               default-scheduler  Successfully assigned kube-system/my-scheduler-64576b7897-8b549 to minikube
  Normal   Pulled     2s (x4 over 47s)  kubelet, minikube  Container image "gcr.io/my-gcp-project-239900/my-kube-scheduler:1.0" already present on machine
  Normal   Created    2s (x4 over 47s)  kubelet, minikube  Created container kube-second-scheduler
  Normal   Started    2s (x4 over 47s)  kubelet, minikube  Started container kube-second-scheduler
  Warning  BackOff    1s (x6 over 45s)  kubelet, minikube  Back-off restarting failed container

当我尝试查看此Pod的日志时,出现此错误消息:

 standard_init_linux.go:207: exec user process caused "exec format error"

我的Dockerfile与指南有点不同,它看起来像:
FROM busybox
ADD ./_output/local/bin/darwin/amd64/kube-scheduler /usr/local/bin/kube-scheduler

我变了
ADD ./_output/dockerized/bin/linux/amd64/kube-scheduler /usr/local/bin/kube-scheduler

进入
ADD ./_output/local/bin/darwin/amd64/kube-scheduler /usr/local/bin/kube-scheduler

因为./_output/local/bin/darwin/amd64/kube-scheduler是调度程序文件的正确位置。如果有人能告诉我为什么会这样,我也将不胜感激。

一些更新

文件位置不同

按照指南,我在shell中键入了这些命令

git clone https://github.com/kubernetes/kubernetes.git
cd kubernetes
make

通过执行makeMakefile文件将在特定路径(包括我们想要的kube-scheduler)中生成kubernetes exec文件。生成路径与您的系统有关。由于我使用 minikube 来运行kubernetes和docker,因此它在 darwin(amd64)上运行。我认为这就是我的路线与指南不同的原因。

“exec格式错误”

对于这个错误

 standard_init_linux.go:207: exec user process caused "exec format error"

我发现this issue建议在尝试在容器中运行命令之前添加#!/bin/bash。这告诉系统将命令视为bash命令。在busybox中,它应该是/bin/sh。 (我对 shell 语言机制了解不多,如果我错了,请纠正我)

所以我在my-sheduler.yaml中更改了这些行:
- command:
 - /usr/local/bin/kube-scheduler
 - --address=0.0.0.0
 - --leader-elect=false
 - --scheduler-name=my-scheduler

进入
- command:
 - /bin/sh
 - /usr/local/bin/kube-scheduler
 - --address=0.0.0.0
 - --leader-elect=false
 - --scheduler-name=my-schedule

现在,my-sheduler容器仍然失败,并出现CrashLoopBackOff错误。
好消息是执行kubectl logs时现在有了日志。
坏消息是这样的日志不可读

/usr/local/bin/kube-scheduler: line 1: ����: not found
/usr/local/bin/kube-scheduler: line 2: syntax error: unexpected ")"

我认为这是由于docker镜像中发生了某些事情而发生的。但是由于我是从kubernetes github page直接使用脚本,所以应该没有任何错误。

当我运行docker run -it {my-image-id} /bin/sh并进入镜像并运行exec kube-scheduler文件时,将显示相同的日志。

我无法弄清楚GO脚本中的内容会导致此问题。

另一种选择

我最终尝试了另一种构建自定义调度程序的方法。

我遵循了本教程:https://www.youtube.com/watch?v=IYcL0Un1io0&t=1807s

您可以在此处找到源代码:https://github.com/kelseyhightower/scheduler

与官方指南相比,这是更清晰的信息(在官方指南中,您必须构建整个程序才能获取调度程序文件)。

如果有人遇到相同的问题,希望这对您有所帮助。

最佳答案

这完全看起来像是您使用darwin kube-scheduler go二进制文件在Linux container中运行。

您可能在Mac上运行了此命令:

git clone https://github.com/kubernetes/kubernetes.git
cd kubernetes
make

它创建了darwin二进制文件,而不是Linux二进制文件。我会尝试从Linux机器上运行它。或将make目标更改为使用 GOOS=linux and GOARCH=amd64

请注意,在撰写本文时,K8主要支持Linux,仅支持Windows节点。

关于go - 遵循 “Configure Multiple Schedulers” Kubernetes指南时发生错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56030098/

10-15 19:22