Support ephemral storage on EKS
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-images |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
In EKS, Using instance storage option can help faster than ebs.
Amazon EKS AMI support control ephemeral-storage to easy way.
https:/
If Ubuntu EKS AMI or Ubuntu AMI include this shellscript, very helpful for operating ephemeral storage in AWS EC2.
# content of /bin/setup-
```
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
err_report() {
echo "Exited with error on line $1"
}
trap 'err_report $LINENO' ERR
print_help() {
echo "usage: $0 <raid0 | mount>"
echo "Sets up Amazon EC2 Instance Store NVMe disks"
echo ""
echo "-d, --dir directory to mount the filesystem(s) (default: /mnt/k8s-disks/)"
echo "-h, --help print this help"
}
# Sets up a RAID-0 of NVMe instance storage disks, moves
# the contents of /var/lib/kubelet and /var/lib/containerd
# to the new mounted RAID, and bind mounts the kubelet and
# containerd state directories.
maybe_raid0() {
local md_name=
local md_device=
local md_config=
local array_mount_
mkdir -p "$(dirname "${md_config}")"
if [[ ! -s "${md_config}" ]]; then
mdadm --create --force --verbose \
"
--level=0 \
-
-
"
while [ -n "$(mdadm --detail "${md_device}" | grep -ioE 'State :.*resyncing')" ]; do
echo "Raid is resyncing..."
sleep 1
done
mdadm --detail --scan > "${md_config}"
fi
## Check if the device symlink has changed on reboot to include a homehost identifier
local current_
if [[ ! -z ${current_
md_
fi
# Format the array if not already formatted.
if [[ -z "$(lsblk "${md_device}" -o fstype --noheadings)" ]]; then
## By default, mkfs tries to use the stripe unit of the array (512k),
## for the log stripe unit, but the max log stripe unit is 256k.
## So instead, we use 32k (8 blocks) to avoid a warning of breaching the max.
## mkfs.xfs defaults to 32k after logging the warning since the default log buffer size is 32k.
mkfs.xfs -l su=8b "${md_device}"
fi
## Create the mount directory
mkdir -p "${array_
local dev_uuid=$(blkid -s UUID -o value "${md_device}")
local mount_unit_
cat > "/etc/systemd/
[Unit]
Description=Mount EC2 Instance Store NVMe disk RAID0
[Mount]
What=
Where=
Type=xfs
Options=
[Install]
WantedBy=
EOF
systemd-analyze verify "${mount_
systemctl enable "${mount_
prev_running=""
needs_linked=""
for unit in "kubelet" "containerd"; do
## Check if the bind mount from the RAID already exists
if [[ "$(systemctl is-active var-lib-
# Check if components that depend on the RAID are running and, if so, stop them
if systemctl is-active "${unit}" > /dev/null 2>&1; then
fi
needs_
fi
done
## Check if /var/log/pods has been bind mounted and make sure kubelet is stopped
if [[ "$(systemctl is-active var-log-
if systemctl is-active "kubelet" > /dev/null 2>&1; then
prev_
fi
needs_linked+=" /var/log/pods"
fi
if [[ ! -z "${prev_running}" ]]; then
systemctl stop ${prev_running}
fi
# Transfer state directories to the array, if they exist.
for mount_point in ${needs_linked}; do
local unit="$(basename "${mount_point}")"
local array_mount_
mkdir -p "${mount_point}"
echo "Copying ${mount_point}/ to ${array_
cp -a "${mount_point}/" "${array_
local mount_unit_
cat > "/etc/systemd/
[Unit]
Descripti
[Mount]
What=
Where=
Type=none
Options=bind
[Install]
WantedBy=
EOF
systemd-analyze verify "${mount_
systemctl enable "${mount_
done
if [[ ! -z "${prev_running}" ]]; then
systemctl start ${prev_running}
fi
}
# Mounts and creates xfs file systems on all EC2 instance store NVMe disks
# without existing file systems. Mounts in /mnt/k8s-
maybe_mount() {
idx=1
for dev in "${EPHEMERAL_
if [[ -z "$(lsblk "${dev}" -o fstype --noheadings)" ]]; then
mkfs.xfs -l su=8b "${dev}"
fi
if [[ ! -z "$(lsblk "${dev}" -o MOUNTPOINT --noheadings)" ]]; then
echo "${dev} is already mounted."
continue
fi
local mount_point=
local mount_unit_
mkdir -p "${mount_point}"
cat > "/etc/systemd/
[Unit]
Description
[Mount]
What=${dev}
Where=
Type=xfs
Options=
[Install]
WantedBy=
EOF
systemd-analyze verify "${mount_
systemctl enable "${mount_
idx=$((idx + 1))
done
}
## Main logic
MNT_DIR=
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h | --help)
print_help
exit 0
;;
-d | --dir)
MNT_DIR="$2"
shift
shift
;;
*) # unknown option
POSITIONA
shift # past argument
;;
esac
done
set +u
set -- "${POSITIONAL[@]}" # restore positional parameters
DISK_SETUP="$1"
set -u
if [[ "${DISK_SETUP}" != "raid0" && "${DISK_SETUP}" != "mount" ]]; then
echo "Valid disk setup options are: raid0 or mount"
exit 1
fi
disks=($(find -L /dev/disk/by-id/ -xtype l -name '*NVMe_
## Bail early if there are no ephemeral disks to setup
if [[ "${#disks[@]}" -eq 0 ]]; then
echo "no ephemeral disks found, skipping disk setup"
exit 0
fi
if [ "$(id --user)" -ne 0 ]; then
echo "Must be run as root"
exit 1
fi
## Get devices of NVMe instance storage ephemeral disks
EPHEMERAL_
case "${DISK_SETUP}" in
"raid0")
maybe_raid0
echo "Successfully setup RAID-0 consisting of ${EPHEMERAL_
;;
"mount")
maybe_mount
echo "Successfully setup disk mounts consisting of ${EPHEMERAL_
;;
esac
```
Changed in cloud-images: | |
status: | New → Confirmed |
tags: | added: cpc-3580 |