配置 kubelet 在 coreos 上使用 rkt 而不是 docker

configure kubelet to use rkt instead of docker on coreos

我正在尝试按照 https://coreos.com/kubernetes/docs/latest/deploy-master.html 中的描述部署主节点 在 CoreOS 测试版 (1153.4.0) 上。

我正在使用以下 kubeconfig yaml 文件:

 current-context: tuxin-coreos-context
 apiVersion: v1
 clusters:
 - cluster:
     certificate-authority: /etc/kubernetes/ssl/ca.pem
     server: https://coreos-2.tux-in.com:443
   name: tuxin-coreos-cluster
 contexts:
 - context:
     cluster: tuxin-coreos-cluster
   name: tuxin-coreos-context
 kind: Config
 preferences:
   colors: true
 users:
 - name: ufk
   user:
     client-certificate: /etc/kubernetes/ssl/apiserver.pem
     client-key: /etc/kubernetes/ssl/apiserver-key.pem

我正在使用 KUBELET_VERSION v1.4.0-beta.10_coreos.0

systemctl cat kubelet returns 以下:

/etc/systemd/system/kubelet.服务

[Service]
ExecStartPre=/usr/bin/mkdir -p /etc/kubernetes/manifests
ExecStartPre=/usr/bin/mkdir -p /var/log/containers

Environment=KUBELET_VERSION=v1.4.0-beta.10_coreos.0
Environment="RKT_OPTS=--volume var-log,kind=host,source=/var/log \
  --mount volume=var-log,target=/var/log \
  --volume dns,kind=host,source=/etc/resolv.conf \
  --mount volume=dns,target=/etc/resolv.conf"

ExecStart=/usr/lib/coreos/kubelet-wrapper \
  --kubeconfig=/var/lib/kubelet/kubeconfig  \
  --network-plugin-dir=/etc/kubernetes/cni/net.d   \
  --network-plugin=cni   \
  --register-schedulable=false   \
  --allow-privileged=true  \
  --pod-manifest-path=/etc/kubernetes/manifests   \
  --hostname-override=coreos-2.tux-in.com   \
  --container-runtime=rkt
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

journalctl -b -u kubelet returns

Sep 26 17:58:53 coreos-2.tux-in.com systemd[1]: Starting kubelet.service...
Sep 26 17:58:53 coreos-2.tux-in.com systemd[1]: Started kubelet.service.
Sep 26 17:58:53 coreos-2.tux-in.com kubelet-wrapper[1725]: image: using image from file /usr/lib64/rkt/stage1-images/stage1-fly.aci
Sep 26 17:58:54 coreos-2.tux-in.com kubelet-wrapper[1725]: image: using image from local store for image name quay.io/coreos/hyperkube:v1.4.0-beta.10_coreos.0
Sep 26 17:59:11 coreos-2.tux-in.com kubelet-wrapper[1725]: W0926 17:59:11.807917    1725 server.go:383] No API client: no api servers specified
Sep 26 17:59:12 coreos-2.tux-in.com kubelet-wrapper[1725]: I0926 17:59:12.871488    1725 manager.go:140] cAdvisor running in container: "/system.slice/kubelet.service"
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: I0926 17:59:14.454499    1725 fs.go:116] Filesystem partitions: map[/dev/sda9:{mountpoint:/var/lib/docker major:8 minor:9 fsType:ext4 blockSize:0} /dev/sda3:{mountpoint:/etc/ssl/certs major:8 minor:3 fsType:ext4 blockSize:0} overlay:{mountpoint:/ major:0 minor:54 fsType:overlay blockSize:0}]
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: I0926 17:59:14.458559    1725 manager.go:195] Machine: {NumCores:8 CpuFrequency:3060000 MemoryCapacity:4145504256 MachineID:f3e41f31b6024d84806ddf3a54075add SystemUUID:00000000-0000-0000-0000-1C6F653E6F72 BootID:ca4acb17-baa6-4863-acdb-2db06609b0d8 Filesystems:[{Device:/dev/sda3 Capacity:1031946240 Type:vfs Inodes:260096 HasInodes:true} {Device:overlay Capacity:984373800960 Type:vfs Inodes:61054976 HasInodes:true} {Device:/dev/sda9 Capacity:113819422720 Type:vfs Inodes:28536576 HasInodes:true}] DiskMap:map[8:0:{Name:sda Major:8 Minor:0 Size:120034123776 Scheduler:cfq} 8:16:{Name:sdb Major:8 Minor:16 Size:1000204886016 Scheduler:cfq} 8:32:{Name:sdc Major:8 Minor:32 Size:3000592982016 Scheduler:cfq} 8:48:{Name:sdd Major:8 Minor:48 Size:2000398934016 Scheduler:cfq} 8:64:{Name:sde Major:8 Minor:64 Size:1000204886016 Scheduler:cfq}] NetworkDevices:[{Name:enp4s0 MacAddress:1c:6f:65:3e:6f:72 Speed:1000 Mtu:1500} {Name:flannel.1 MacAddress:6a:5e:8b:1d:00:17 Speed:0 Mtu:1450}] Topology:[{Id:0 Memory:4145504256 Cores:[{Id:0 Threads:[0 4] Caches:[{Size:32768 Type:Data Level:1} {Size:32768 Type:Instruction Level:1} {Size:262144 Type:Unified Level:2}]} {Id:1 Threads:[1 5] Caches:[{Size:32768 Type:Data Level:1} {Size:32768 Type:Instruction Level:1} {Size:262144 Type:Unified Level:2}]} {Id:2 Threads:[2 6] Caches:[{Size:32768 Type:Data Level:1} {Size:32768 Type:Instruction Level:1} {Size:262144 Type:Unified Level:2}]} {Id:3 Threads:[3 7] Caches:[{Size:32768 Type:Data Level:1} {Size:32768 Type:Instruction Level:1} {Size:262144 Type:Unified Level:2}]}] Caches:[{Size:8388608 Type:Unified Level:3}]}] CloudProvider:Unknown InstanceType:Unknown InstanceID:None}
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: I0926 17:59:14.459359    1725 manager.go:201] Version: {KernelVersion:4.7.1-coreos ContainerOsVersion:CoreOS 1153.4.0 (MoreOS) DockerVersion:1.11.2 CadvisorVersion: CadvisorRevision:}
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: W0926 17:59:14.460736    1725 server.go:613] No api server defined - no events will be sent to API server.
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: I0926 17:59:14.460794    1725 kubelet.go:255] Adding manifest file: /etc/kubernetes/manifests
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: W0926 17:59:14.463983    1725 kubelet_network.go:64] Hairpin mode set to "promiscuous-bridge" but container runtime is "rkt", ignoring
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: I0926 17:59:14.464034    1725 kubelet.go:516] Hairpin mode set to "none"
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: Error: failed to run Kubelet: failed to create kubelet: cannot find rkt binary: exec: "rkt": executable file not found in $PATH
Sep 26 17:59:14 coreos-2.tux-in.com kubelet-wrapper[1725]: failed to run Kubelet: failed to create kubelet: cannot find rkt binary: exec: "rkt": executable file not found in $PATH
Sep 26 17:59:14 coreos-2.tux-in.com systemd[1]: kubelet.service: Main process exited, code=exited, status=1/FAILURE
Sep 26 17:59:14 coreos-2.tux-in.com systemd[1]: kubelet.service: Unit entered failed state.
Sep 26 17:59:14 coreos-2.tux-in.com systemd[1]: kubelet.service: Failed with result 'exit-code'.
Sep 26 17:59:24 coreos-2.tux-in.com systemd[1]: kubelet.service: Service hold-off time over, scheduling restart.
Sep 26 17:59:24 coreos-2.tux-in.com systemd[1]: Stopped kubelet.service.

我试图指定 rkt 的特定路径,我尝试使用我的核心 os 上的相同路径,即 /bin/rkt 但它无法在那里找到二进制文件。超立方体图像是否由于某种原因缺少 rkt 二进制文件?

更新

好吧,我试图进一步调试这个问题,但又陷入了死胡同。

我尝试 运行 手动检查所有内容以查看问题出在哪里..

所以我设置了以下环境变量:

export KUBELET_VERSION=v1.4.0_coreos.0
export RKT_OPTS=--volume var-log,kind=host,source=/var/log \
 --mount volume=var-log,target=/var/log \
 --volume dns,kind=host,source=/etc/resolv.conf \
 --mount volume=dns,target=/etc/resolv.conf

然后我将 /usr/lib/coreos/kubelet-wrapper 文件复制到我的主目录并将其修改为 运行 bash 改为:

...
${KUBELET_ACI}:${KUBELET_VERSION} --exec=/bin/bash

然后我 运行 kubelet 具有以下参数:

./kubelet-wrapper   --kubeconfig=/var/lib/kubelet/kubeconfig    --network-plugin-dir=/etc/kubernetes/cni/net.d     --network-plugin=cni     --register-schedulable=false     --allow-privileged=true    --pod-manifest-path=/etc/kubernetes/manifests     --hostname-override=coreos-2.tux-in.com     --container-runtime=rkt

然后在得到 bash 提示后,我 运行 kubelet 使用以下参数:

./kubelet --kubeconfig=/var/lib/kubelet/kubeconfig  \
  --network-plugin-dir=/etc/kubernetes/cni/net.d   \
  --network-plugin=cni   \
  --register-schedulable=false   \
  --allow-privileged=true  \
  --pod-manifest-path=/etc/kubernetes/manifests   \
  --hostname-override=coreos-2.tux-in.com   \
  --container-runtime=rkt

我再次收到 cannot find rkt binary 错误消息。 我尝试通过 运行ning find / | grep rkt$ 在该容器中找到 rkt 二进制文件,但没有找到 rkt 二进制文件。

现在,手动过程将 docker 换成 rkt 有点棘手,但是 coreos-kubernetes 中的自动化脚本,例如 kube-aws 工具或 Vagrant 文档可以这口井

在您的特定情况下,需要使用 RKT_OPTS 从主机将 rkt 二进制文件安装到包装器中(这意味着它会自动更新),然后您需要添加更多标志到 API 服务器:

--container-runtime=rkt

--rkt-api-endpoint=HOST:PORT

--rkt-path=PATH_TO_RKT_BINARY

--rkt-stage1-image=STAGE1

随着 rkt + kubernetes 的调试过程和最佳实践变得更加清晰,CoreOS 打算随着时间的推移提供更好的手动说明。

使用 rkt 设置 kubernetes 作为 运行time 的最简单方法是使用找到的脚本 here。正如 Rob 所说,您看到该错误的原因是因为 kubelet 在容器中 运行 而在主机上看不到 /usr/bin/rkt

现在,让容器化的 kubelet 与主机上的 rkt 运行time 正确对话有点复杂。仅仅将 rkt 二进制文件绑定挂载到 kubelet 容器中是不够的。详细信息已在 PR.

中捕获

我们花了一些努力使这一切在 coreos-kubernetes 存储库中顺利运行并测试了结果。如果您使用该存储库中的脚本,只需将 CONTAINER_RUNTIME 环境变量设置为 rkt.