gpt4 book ai didi

kubernetes - 在 Kubernetes (GKE) 中的一个节点上组合多个本地 SSD

转载 作者:行者123 更新时间:2023-12-05 09:14:10 24 4
gpt4 key购买 nike

我的容器所需的数据太大,无法放在一个本地 SSD 上。我还需要从我的容器中访问 SSD 作为一个文件系统。所以我需要附加多个。我如何组合它们(单个分区、RAID0 等)并使它们作为容器中的一个卷安装可访问?

此链接分享如何安装 SSD https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/local-ssd到挂载路径。我不确定您将如何合并多个。

编辑

问题是如何在 GKE 的单个节点上“组合”多个单独安装的 SSD 设备。

最佳答案

WARNING this is experimental and not intended for production use without knowing what you are doing and only tested on gke version 1.16.x.

该方法包括一个使用 configmapdaemonset 来使用 nsenter(带有等待技巧)主机命名空间和特权访问,因此您可以管理设备。特别是对于 GKE Local SSD,我们可以卸载这些设备,然后对它们进行 raid0。 InitContainer 用于肮脏的工作,因为这种类型的任务似乎最明显的是你需要标记完成的东西,然后终止特权容器访问(甚至 Pod)。这是它是如何完成的。

该示例假设有 16 个 SSD,但是,您需要根据需要调整硬编码值。另外,确保您的操作系统镜像要求,我使用 Ubuntu。还要确保您使用的 GKE 版本在 sd[b] 启动 local-ssd

配置图

apiVersion: v1
kind: ConfigMap
metadata:
name: local-ssds-setup
namespace: search
data:
setup.sh: |
#!/bin/bash
# returns exit codes: 0 = found, 1 = not found
isMounted() { findmnt -rno SOURCE,TARGET "$1" >/dev/null;} #path or device

# existing disks & mounts
SSDS=(/dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo /dev/sdp /dev/sdq)

# install mdadm utility
apt-get -y update && apt-get -y install mdadm --no-install-recommends
apt-get autoremove

# OPTIONAL: determine what to do with existing, I wipe it here
if [ -b "/dev/md0" ]
then
echo "raid array already created"

if isMounted "/dev/md0"; then
echo "already mounted - unmounting"
umount /dev/md0 &> /dev/null || echo "soft error - assumed device was mounted"
fi

mdadm --stop /dev/md0
mdadm --zero-superblock "${SSDS[@]}"
fi

# unmount disks from host filesystem
for i in {0..15}
do
umount "${SSDS[i]}" &> /dev/null || echo "${SSDS[i]} already unmounted"
done

if isMounted "/dev/sdb";
then
echo ""
echo "unmount failure - prevent raid0" 1>&2
exit 1
fi

# raid0 array
yes | mdadm --create /dev/md0 --force --level=0 --raid-devices=16 "${SSDS[@]}"

echo "raid array created"

# format
mkfs.ext4 -F /dev/md0

# mount, change /mnt/ssd-array to whatever
mkdir -p /mnt/ssd-array
mount /dev/md0 /mnt/ssd-array
chmod a+w /mnt/ssd-array

wait.sh: |
#!/bin/bash
while sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do sleep 1; done

DeamonSet pod 规范

spec:
hostPID: true
nodeSelector:
cloud.google.com/gke-local-ssd: "true"
volumes:
- name: setup-script
configMap:
name: local-ssds-setup
- name: host-mount
hostPath:
path: /tmp/setup
initContainers:
- name: local-ssds-init
image: marketplace.gcr.io/google/ubuntu1804
securityContext:
privileged: true
volumeMounts:
- name: setup-script
mountPath: /tmp
- name: host-mount
mountPath: /host
command:
- /bin/bash
- -c
- |
set -e
set -x

# Copy setup script to the host
cp /tmp/setup.sh /host

# Copy wait script to the host
cp /tmp/wait.sh /host

# Wait for updates to complete
/usr/bin/nsenter -m/proc/1/ns/mnt -- chmod u+x /tmp/setup/wait.sh

# Give execute priv to script
/usr/bin/nsenter -m/proc/1/ns/mnt -- chmod u+x /tmp/setup/setup.sh

# Wait for Node updates to complete
/usr/bin/nsenter -m/proc/1/ns/mnt /tmp/setup/wait.sh

# If the /tmp folder is mounted on the host then it can run the script
/usr/bin/nsenter -m/proc/1/ns/mnt /tmp/setup/setup.sh
containers:
- image: "gcr.io/google-containers/pause:2.0"
name: pause

关于kubernetes - 在 Kubernetes (GKE) 中的一个节点上组合多个本地 SSD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54751882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com