[英]Restarting Docker daemon on host node from within Kubernetes pod
目標:在 GKE 上重啟 Docker 守護進程
問題:無法連接到總線
背景在 Google Kubernetes Engine (GKE) 上,我嘗試重新啟動主機節點的 Docker 守護進程,以便在具有 GPU 的節點上為 Kubernetes啟用Nvidia GPU 遙測。 我已經正確分離只是GPU節點正常,而我能夠通過具有運行主機節點上的每個命令DaemonSet
運行initContainer
繼與daemonSets自動自舉Kubernetes引擎節點指南。
但是,在運行時,以下 pod 不允許我連接到 Docker 守護進程:
apiVersion: v1
kind: Pod
metadata:
name: debug
namespace: gpu-monitoring
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: cloud.google.com/gke-accelerator
operator: Exists
containers:
- command:
- sleep
- "86400"
env:
- name: ROOT_MOUNT_DIR
value: /root
image: docker.io/ubuntu:18.04
imagePullPolicy: IfNotPresent
name: node-initializer
securityContext:
privileged: true
volumeMounts:
- mountPath: /root
name: root
- mountPath: /scripts
name: entrypoint
- mountPath: /run
name: run
volumes:
- hostPath:
path: /
type: ""
name: root
- configMap:
defaultMode: 484
name: nvidia-container-toolkit-installer-entrypoint
name: entrypoint
- hostPath:
path: /run
type: ""
name: run
用戶是0
,而/run/user
是1003
和1002
。
為了驗證與根 Kubernetes (k8s) 節點的連接和交互,運行以下命令:
root@debug:/# chroot "${ROOT_MOUNT_DIR}" ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 226124 9816 ? Ss Oct13 0:27 /sbin/init
問題
兩個圖像
當嘗試與底層 Kubernetes (k8s) 節點交互以重新啟動 Docker 守護程序時,我得到以下信息:
root@debug:/# ls /run/dbus
system_bus_socket
root@debug:/# ROOT_MOUNT_DIR="${ROOT_MOUNT_DIR:-/root}"
root@debug:/# chroot "${ROOT_MOUNT_DIR}" systemctl status docker
Failed to connect to bus: No data available
嘗試在主機節點上啟動 dbus 時:
root@debug:/# export XDG_RUNTIME_DIR=/run/user/`id -u`
root@debug:/# export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"
root@debug:/# chroot "${ROOT_MOUNT_DIR}" /etc/init.d/dbus start
Failed to connect to bus: No data available
圖片:solita/ubuntu-systemd
當嘗試使用相同的 k8s pod 配置運行命令時,除了在 solita solita/ubuntu-systemd
映像內,結果如下:
root@debug:/# /etc/init.d/dbus start
[....] Starting dbus (via systemctl): dbus.serviceRunning in chroot, ignoring request: start
. ok
嘗試的配置變體我試圖在幾乎所有組合中更改以下內容,但無濟於事:
docker.io/solita/ubuntu-systemd:18.04
shareProcessNamespace: true
/dev
、 /proc
、 /sys
/run
到/run/dbus
,和/run/systemd
所以答案是一個奇怪的解決方法,這出乎意料。 為了重新啟動 Docker 守護進程,首先要為 pod 打一個防火牆孔,以便連接到主機節點。 接下來,使用gcloud compute ssh
和 ssh 進入節點並通過遠程 ssh 命令重新啟動:
apt-get update
apt-get install -y \
apt-transport-https \
curl \
gnupg \
lsb-release \
ssh
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
apt-get update
apt-get install -y google-cloud-sdk
CLUSTER_NAME="$(curl -sS http://metadata/computeMetadata/v1/instance/attributes/cluster-name -H "Metadata-Flavor: Google")"
NODE_NAME="$(curl -sS http://metadata.google.internal/computeMetadata/v1/instance/name -H 'Metadata-Flavor: Google')"
FULL_ZONE="$(curl -sS http://metadata.google.internal/computeMetadata/v1/instance/zone -H 'Metadata-Flavor: Google' | awk -F "/" '{print $4}')"
MAIN_ZONE=$(echo $FULL_ZONE | sed 's/\(.*\)-.*/\1/')
gcloud compute ssh \
--internal-ip $NODE_NAME \
--zone=$FULL_ZONE \
-- "sudo systemctl restart docker"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.