feat: Update k3s VM startup script with improved disk formatting and user configuration
This commit is contained in:
parent
3e1146ee9d
commit
4a8ae2d1ff
1 changed files with 57 additions and 12 deletions
|
|
@ -1,12 +1,32 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Format the disk if not already formatted
|
# Format the k3s disk if not already formatted
|
||||||
|
|
||||||
|
# This command creates an ext4 filesystem on the specified
|
||||||
|
# disk with no reserved space for root, forces the operation,
|
||||||
|
# fully initializes inode tables and the journal, and enables
|
||||||
|
# discard/TRIM for better performance on SSDs or
|
||||||
|
# thin-provisioned storage.
|
||||||
if ! lsblk | grep -q "/mnt/disks/k3s"; then
|
if ! lsblk | grep -q "/mnt/disks/k3s"; then
|
||||||
mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-k3s-disk
|
mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-k3s-disk
|
||||||
mkdir -p /mnt/disks/k3s
|
mkdir -p /var/lib/rancher/k3s
|
||||||
mount -o discard,defaults /dev/disk/by-id/google-k3s-disk /mnt/disks/k3s
|
mount -o discard,defaults /dev/disk/by-id/google-k3s-disk /var/lib/rancher/k3s
|
||||||
chmod a+w /mnt/disks/k3s
|
chmod a+w /var/lib/rancher/k3s
|
||||||
fi
|
fi
|
||||||
|
# A disk named k3s-disk in your Terraform configuration will
|
||||||
|
# appear as /dev/disk/by-id/google-k3s-disk.
|
||||||
|
|
||||||
|
# Format the app-data-disk if not already formatted
|
||||||
|
if ! lsblk | grep -q "/mnt/disks/app-data"; then
|
||||||
|
mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-app-data-disk
|
||||||
|
mkdir -p /mnt/disks/app-data
|
||||||
|
mount -o discard,defaults /dev/disk/by-id/google-app-data-disk /mnt/disks/app-data
|
||||||
|
chmod a+w /mnt/disks/app-data
|
||||||
|
fi
|
||||||
|
# Similarly, a disk named app-data-disk will appear as /dev/
|
||||||
|
# disk/by-id/google-app-data-disk.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ensure only run once
|
# ensure only run once
|
||||||
if [[ -f /etc/startup_was_launched ]]; then exit 0; fi
|
if [[ -f /etc/startup_was_launched ]]; then exit 0; fi
|
||||||
|
|
@ -21,13 +41,38 @@ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scrip
|
||||||
chmod 700 get_helm.sh
|
chmod 700 get_helm.sh
|
||||||
/bin/bash get_helm.sh
|
/bin/bash get_helm.sh
|
||||||
|
|
||||||
# bashrc config
|
# user bashrc config
|
||||||
rc=/root/.bashrc
|
rc=/home/user/.bashrc
|
||||||
echo "alias l='ls -lah'" >> $rc
|
{
|
||||||
echo "alias ll='ls -lh'" >> $rc
|
echo "export KUBECONFIG=~/.kube/config"
|
||||||
echo "alias k=kubectl" >> $rc
|
echo "alias l='ls -lah'"
|
||||||
echo "export dry='--dry-run=client'" >> $rc
|
echo "alias ll='ls -lh'"
|
||||||
echo "export o='-oyaml'" >> $rc
|
echo "alias k=kubectl"
|
||||||
|
echo "export dry='--dry-run=client'"
|
||||||
|
echo "export o='-oyaml'"
|
||||||
|
echo "alias kcd='kubectl config use-context'"
|
||||||
|
echo "source <(kubectl completion bash)"
|
||||||
|
echo "complete -F __start_kubectl k"
|
||||||
|
echo "alias k='kubectl'"
|
||||||
|
} >> $rc
|
||||||
|
|
||||||
|
|
||||||
# Install k3s and configure it to use the persistent disk for data storage
|
# Install k3s and configure it to use the persistent disk for data storage
|
||||||
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--data-dir /mnt/disks/k3s" sh -
|
# curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--data-dir /mnt/disks/k3s" sh -
|
||||||
|
|
||||||
|
k3s_version="v1.32.8+k3s1"
|
||||||
|
curl -sfL https://get.k3s.io \
|
||||||
|
| \
|
||||||
|
INSTALL_K3S_VERSION="$k3s_version" sh -s - server \
|
||||||
|
--cluster-init \
|
||||||
|
--disable traefik \
|
||||||
|
--disable servicelb
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p /home/user/.kube
|
||||||
|
chown user:user /home/user/.kube
|
||||||
|
chmod 700 /home/user/.kube
|
||||||
|
# Copy the kubeconfig file to the user's home directory
|
||||||
|
# for easier access
|
||||||
|
cp /etc/rancher/k3s/k3s.yaml /home/user/.kube/config
|
||||||
|
chown user:user /home/user/.kube/config
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue