Last active
March 30, 2025 03:22
Karpenter EC2NodeClass aws mount nvme /var/lib/containerd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: karpenter.k8s.aws/v1beta1 | |
kind: EC2NodeClass | |
metadata: | |
name: gitlab-runner | |
spec: | |
amiFamily: AL2023 | |
blockDeviceMappings: [] | |
userData: | | |
MIME-Version: 1.0 | |
Content-Type: multipart/mixed; boundary="BOUNDARY" | |
--BOUNDARY | |
Content-Type: text/x-shellscript; charset="us-ascii" | |
#!/bin/bash | |
echo "Running a custom user data script" | |
set -ex | |
yum install -y mdadm nvme-cli rsync | |
systemctl stop containerd | |
nvme_disks=($(nvme list | grep "Amazon EC2 NVMe Instance Storage" | awk -F'[[:space:]][[:space:]]+' '{print $1}')) | |
if [[ ${#nvme_disks[@]} -ge 2 ]]; then | |
mdadm --create --verbose /dev/md0 --level=0 --raid-devices=${#nvme_disks[@]} ${nvme_disks[*]} && | |
mkfs.ext4 -F /dev/md0 && | |
mv /var/lib/containerd/ /var/lib/containerd-original && | |
mkdir /var/lib/containerd && | |
mount /dev/md0 /var/lib/containerd && | |
rsync -a /var/lib/containerd-original/ /var/lib/containerd/ && | |
rm -rf /var/lib/containerd-original && | |
chmod 750 /var/lib/containerd && | |
systemctl start containerd | |
else | |
echo "Not enough NVMe disks available for RAID 0 configuration." | |
fi | |
--BOUNDARY-- |
Updated new aws amis, need /var/lib/containerd content to boot k8s due to prepulled images.
FYI - with EKS AL2023 optimized AMIs, you don't need to do all of that. Instead you can use nodeadm
to do this with the following:
apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
metadata:
name: gitlab-runner
spec:
amiFamily: AL2023
blockDeviceMappings: []
userData: |
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="BOUNDARY"
--BOUNDARY
Content-Type: application/node.eks.aws
---
apiVersion: node.eks.aws/v1alpha1
kind: NodeConfig
spec:
instance:
localStorage:
strategy: RAID0
--BOUNDARY--
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Happy about applause on:
https://medium.com/@IT_Supertramp/how-to-use-aws-nvme-via-karpenter-ec2nodeclass-c6462928dc67