# rke2-base-config.yaml - Base Flatcar + RKE2 setup
variant: flatcar
version: 1.0.0
storage:
  files:
    - path: /etc/hostname
      mode: 0644
      contents:
        inline: rke2-node
    - path: /etc/rancher/rke2/config.yaml
      mode: 0644
      contents:
        inline: |
          tls-san:
            - $(hostname -I | cut -d' ' -f1)
          write-kubeconfig-mode: "0644"
    - path: /opt/setup-rke2.sh
      mode: 0755
      contents:
        inline: |
          #!/bin/bash
          # Install RKE2
          curl -sfL https://get.rke2.io | sh -
          systemctl enable rke2-server.service

          # Create symlinks for kubectl and crictl
          ln -s /var/lib/rancher/rke2/bin/kubectl /usr/local/bin/kubectl
          ln -s /var/lib/rancher/rke2/bin/crictl /usr/local/bin/crictl

          mkdir -p /root/.kube
          ln -sf /etc/rancher/rke2/rke2.yaml /root/.kube/config

systemd:
  units:
    - name: rke2-setup.service
      enabled: true
      contents: |
        [Unit]
        Description=RKE2 Setup
        After=network-online.target
        Wants=network-online.target

        [Service]
        Type=oneshot
        ExecStart=/opt/setup-rke2.sh
        RemainAfterExit=yes

        [Install]
        WantedBy=multi-user.target
