遵循“配置多个调度程序” Kubernetes指南时发生错误

When I trying to follow the Kubernetes Configure Multiple Schedulers guide, I cannot successfully get the my-scheduler pod running.

I succeed to build the image and push it to a registry, and the image shows in my docker and Google Could Platform. But when I apply the deployment file to set the pods, the status is CrashLoopBackOff.

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

Here is the output for 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

And when I try to see the log of this pod, this error message appears:

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

And my Dockerfile is bit different from the guide, it looks like:

FROM busybox
ADD ./_output/local/bin/darwin/amd64/kube-scheduler /usr/local/bin/kube-scheduler

I changed

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

into

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

because ./_output/local/bin/darwin/amd64/kube-scheduleris where the scheduler file acctually located. I would also appreciate it if anyone could tell me why would this happen.


Some Updates

Different file location

Following the guide, I typed these command in my shell

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

by executing make, the Makefilefile will generate the kubernetes exec files in certain path (including the kube-scheduler we want). And the generation path is related to your system. Since I'm using minikube to run kubernetes and docker, and it runs on darwin(amd64). I think that's the reason why my path is different from the guide.

The "exec format error"

For this error

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

I find this issue suggesting add the #!/bin/bash before you try to run commands in the container. This tells the system to treat the commands as bash commands. Here in busybox it should be /bin/sh. (I don't know much about shell language mechanism, so correct me if I'm wrong)

So I changed these lines in my-sheduler.yaml:

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

into

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

Now the my-sheduler pods still fail and get the CrashLoopBackOff error. Good news is I now have the log when executing kubectl logs. Bad news is the logs are unreadable like this

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

I assume this happened because of something happened in the docker image. But since I'm using the scrips right from the kubernetes github page, there shouldn't be any bug.

The same log shows up when I run docker run -it {my-image-id} /bin/sh and go into my image and run the exec kube-scheduler file.

I can't figure it out what's in the GO script causes this problem.


Another alternative

I ended up trying another way to build my custom scheduler.

I followed this tutorial: https://www.youtube.com/watch?v=IYcL0Un1io0&t=1807s

And you can find the source code here: https://github.com/kelseyhightower/scheduler

Comparing to the official guide, this one is more clear light (in in official guide you have to build the whole thing to get the scheduler file).

Hope this helps if someone is running into the same problem.

douquanqiao6788
douquanqiao6788 错误“standard_init_linux.go:207:exec用户进程引起的“exec格式错误”可能指向OS体系结构不匹配。如果您在x64平台上编译了二进制文件-那么它必须在x64平台上运行,依此类推。在x86或ARM上运行并尝试在x64上运行-您会看到此错误。
一年多之前 回复
doudui2229
doudui2229 我的意思是0.0.0.0
一年多之前 回复
dqkxo44488
dqkxo44488 感谢您指出了这一点!因为最初我以为端口冲突可能是一个问题,所以我将其更改为尝试一下。使用正确的地址1.1.1.1,它仍然会失败:(
一年多之前 回复
doujuncuo9339
doujuncuo9339 您好标志也不同--address=1.1.1.1--address=0.0.0.0表示所有接口
一年多之前 回复

1个回答



这完全看起来像是您在使用 darwin </ code> kube-scheduler </ code> go 二进制文件运行在 Linux容器中。 </ p>

您可能在Mac上运行了此代码:</ p>

  git clone https://github.com/kubernetes/kubernetes.git
cd kubernetes
make
</ code> </ pre>

哪个创建了 darwin </ code>二进制文件,而不是Linux二进制文件。 我会尝试从Linux机器上运行它。 或更改make目标以使用 GOOS = linux </ code>和 GOARCH = amd64 </ code> 。</ p>

注意,在撰写本文时,K8主要支持Linux,仅支持Windows节点。</ p>
</ div>

展开原文

原文

This totally looks like that you are using the darwin kube-scheduler go binary to run in a Linux container.

You probably ran this on your mac:

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

Which created the darwin binaries and not the Linux binaries. I would try to run that from a Linux box. Or change the make target to use GOOS=linux and GOARCH=amd64.

Note that K8s mainly supports Linux and only Windows nodes as of this writing.

douhui1630
douhui1630 谢谢! 我在执行make之后检查了日志,我认为您是对的。 而且我也在使用minikube,它在darwin(amd64)上运行。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐