Kubernetes:配置自定义的第二个调度器容器无法启动

48次阅读
没有评论

问题描述

在尝试向Kubernetes主节点添加一个静态Pod作为新的调度器时遇到问题。用户已创建了一个YAML文件来定义Pod,Pod已经被创建,并且其状态显示为运行中,但是容器无法启动。
以下是用户的问题描述以及相关信息:

  • 使用kubectl查看的输出:
NAME                                   READY   STATUS    RESTARTS   AGE
my-scheduler                           0/1     Running   5          28m
  • 在事件中看到的原因为:cannot join network of a non-running container,以及最后一个错误事件为:
Startup probe failed: Get "https://127.0.0.1:10251/healthz": http: server gave HTTP response to HTTPS client
  • 用户尝试发送GET请求到HTTP URL时获得了OK的响应,但是HTTPS响应出现错误:
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
  • 用户还尝试获取调度器的日志,并得到了以下输出:
I1016 18:47:15.779350       1 registry.go:173] Registering SelectorSpread plugin
I1016 18:47:15.779753       1 registry.go:173] Registering SelectorSpread plugin
I1016 18:47:15.791161       1 registry.go:173] Registering SelectorSpread plugin
I1016 18:47:15.791191       1 registry.go:173] Registering SelectorSpread plugin
W1016 18:47:15.794300       1 authorization.go:47] Authorization is disabled
W1016 18:47:15.794518       1 authentication.go:40] Authentication is disabled
I1016 18:47:15.794695       1 deprecated_insecure_serving.go:51] Serving healthz insecurely on [::]:10251
  • 用户提供的调度器文件内容如下:
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    component: my-scheduler
    tier: control-plane
  name: my-scheduler
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-scheduler
    - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
    - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
    - --bind-address=127.0.0.1
    - --kubeconfig=/etc/kubernetes/scheduler.conf
    - --leader-elect=false
    - --scheduler-name=my-scheduler
    - --port=10251
    - --secure-port=0
    image: k8s.gcr.io/kube-scheduler:v1.19.0
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10251
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    name: my-scheduler
    resources:
      requests:
        cpu: 100m
    startupProbe:
      failureThreshold: 24
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10251
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    volumeMounts:
    - mountPath: /etc/kubernetes/scheduler.conf
      name: kubeconfig
      readOnly: true
  hostNetwork: true
  priorityClassName: system-node-critical
  volumes:
  - hostPath:
      path: /etc/kubernetes/scheduler.conf
      type: FileOrCreate
    name: kubeconfig
status: {}

用户想知道他做错了什么,以及如何正确配置调度器。

解决方案

请注意以下操作注意版本差异及修改前做好备份。
首先,根据您提供的信息,出现问题的主要原因是调度器容器的健康检查配置以及使用的端口设置。下面我将详细解释并提供解决方案。

问题分析

在您的调度器容器配置中,存在以下问题:
1. 在livenessProbestartupProbe中,您使用了scheme: HTTPS,但是您的容器实际上是在HTTP端口上进行监听。
2. 您在容器的启动参数中设置了--port=10251,这是一个不推荐使用的选项,因为它将不安全地暴露API。

解决方案

为了解决上述问题,您需要对调度器容器的配置进行适当的更改。以下是解决方案的详细步骤:

  1. 在您的调度器容器的livenessProbestartupProbe中,将scheme更改为HTTP,因为您的容器实际上是在HTTP端口上监听的。
  2. 在调度器容器的启动参数中,将--port设置为0,并将--secure-port设置为10251。这样可以安全地暴露API。

下面是根据您提供的配置示例进行修改后的调度器容器配置:

“`yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
component: my-scheduler
tier: control-plane
name: my-scheduler
namespace: kube-system
spec:
containers:
– command:
– kube-scheduler
– –authentication-kubeconfig=/etc/kubernetes/scheduler.conf
– –authorization-kubeconfig=/etc/kubernetes/scheduler.conf
– –bind-address=127.0.0.1
– –kubeconfig=/etc/kubernetes/scheduler.conf
– –leader-elect=false
– –scheduler-name=my-scheduler
– –port=0
– –secure-port=10251
image: k8s.gcr.io/kube-scheduler:v1.19.0
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 8
httpGet:
host: 127.0.0.1
path: /healthz
port:

正文完