Update k0s installation method and kubeconfig setup in cloud-init.yaml

This commit is contained in:
2025-03-23 12:51:47 +01:00
parent 5b5bf25acb
commit cd605de7a9

View File

@@ -73,18 +73,20 @@ runcmd:
- install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl - install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# Install k0s # Install k0s
- curl -sSLf https://get.k0s.sh | sh - curl -sSLf https://get.k0s.sh | sh
- k0s install controller --enable-worker - k0s install controller --single
- systemctl enable --now k0scontroller - systemctl enable --now k0scontroller
# Wait for k3s to be ready # Wait for k0s to be ready
- timeout 300 bash -c 'until k0s kubectl get nodes; do sleep 5; done' - sleep 10
- timeout 300 bash -c 'until test -f /var/lib/k0s/pki/admin.conf; do echo "Waiting for k0s to generate kubeconfig..."; sleep 10; done'
- timeout 300 bash -c 'until k0s kubectl get nodes; do echo "Waiting for k0s nodes..."; sleep 10; done'
# Set up kubeconfig for user # Set up kubeconfig for user
- mkdir -p /home/${username}/.kube - mkdir -p /home/${username}/.kube
- k0s kubeconfig admin > /home/${username}/.kube/config - cp /var/lib/k0s/pki/admin.conf /home/${username}/.kube/config
- chown -R ${username}:${username} /home/${username}/.kube - chown -R ${username}:${username} /home/${username}/.kube
- chmod 600 /home/${username}/.kube/config - chmod 600 /home/${username}/.kube/config
# Set up kubeconfig for git # Set up kubeconfig for git
- mkdir -p /home/git/.kube - mkdir -p /home/git/.kube
- k0s kubeconfig admin > /home/git/.kube/config - cp /var/lib/k0s/pki/admin.conf /home/git/.kube/config
- chown -R git:git /home/git/.kube - chown -R git:git /home/git/.kube
- chmod 600 /home/git/.kube/config - chmod 600 /home/git/.kube/config
# Dotfiles # Dotfiles