Last active
April 10, 2025 08:16
-
-
Save k4mrul/a8e0753d90a9b6e07cd1844aae94d47d to your computer and use it in GitHub Desktop.
cloud init script with kubernetes, helm, kubectl
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
#cloud-config | |
package_update: true | |
packages: | |
- bash-completion | |
- make | |
- g++ | |
- jq | |
write_files: | |
- path: /root/setup.sh | |
permissions: '0755' | |
content: | | |
#!/bin/bash | |
set -e | |
ARCH=$(dpkg --print-architecture) | |
# Install yq | |
wget https://github.com/mikefarah/yq/releases/download/v4.2.0/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 /usr/bin/yq | |
# Install kubectl | |
wget -q "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl" | |
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl | |
rm kubectl | |
# Enable bash completion for kubectl | |
echo "source /usr/share/bash-completion/bash_completion" >> /home/ubuntu/.bashrc | |
echo "complete -F __start_kubectl k" >> /home/ubuntu/.bashrc | |
echo "alias k=kubectl" >> /home/ubuntu/.bashrc | |
# Upgrade k0s | |
curl --proto '=https' --tlsv1.2 -sSf https://get.k0s.sh | sudo sh | |
# Install kubernetes | |
k0s config create > /root/k0s.yaml | |
## we will setup cilium cni | |
sed -i 's/provider: kuberouter/provider: custom/' /root/k0s.yaml | |
## disable kubeproxy (maybe not needed but necessary for laaaarge cluster) for cilium handle routing with eBPF | |
yq eval '.spec.network.kubeProxy.disabled = true' -i /root/k0s.yaml | |
## Install k8s | |
k0s install controller --enable-worker --no-taints -c /root/k0s.yaml | |
k0s start | |
sleep 120 | |
mkdir -p /home/ubuntu/.kube/ | |
k0s kubeconfig admin > /home/ubuntu/.kube/config | |
# Install Helm | |
HELM_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/helm/helm/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') | |
tar -xvz -C /tmp/ -f <(wget -q -O - https://get.helm.sh/helm-${HELM_RELEASE}-linux-${ARCH}.tar.gz) | |
install -o root -g root -m 0755 /tmp/linux-${ARCH}/helm /usr/local/bin/helm | |
# Install Go | |
#wget -q https://go.dev/dl/go1.24.2.linux-${ARCH}.tar.gz | |
#tar -xvf go1.24.2.linux-${ARCH}.tar.gz | |
#mv go /usr/local | |
#echo "export GOROOT=/usr/local/go" >> /etc/bash.bashrc | |
#echo "export PATH=\$GOPATH/bin:\$GOROOT/bin:\$PATH" >> /etc/bash.bashrc | |
#ln -sf /usr/local/go/bin/go /bin/go | |
# Install Docker | |
#curl -fsSL get.docker.com -o get-docker.sh | |
#sudo sh get-docker.sh | |
#sudo systemctl start docker | |
#sudo systemctl enable docker | |
# Add ubuntu user to docker group | |
#sudo usermod -aG docker ubuntu | |
runcmd: | |
- [ bash, /root/setup.sh ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment