# 1. Installa RKE2 (script ufficial)
curl -sfL https://get.rke2.io | sh -
sudo systemctl enable rke2-server.service

# 2. Crea config (personalizza token e tls-san se serve)
sudo mkdir -p /etc/rancher/rke2
sudo tee /etc/rancher/rke2/config.yaml > /dev/null <<EOF

# RKE2 Server Configuration - Additional Master
server: https://POC-Master0:9345  # Direct connection for initial join
token: "K10b8b252de84e5aab8bc1d2a8e4aad3e329ee84d638892b8638de0260b7cb8212a::server:34b189ab7b91fc924500ba0b3608b80b"
write-kubeconfig-mode: "0644"

# Same TLS SANs as master-1 - consistency is crucial!
tls-san:
  - "POC-Kube-Balancer" 
  - "10.20.1.100"
  - "POC-Master0"
  - "10.20.1.101"
  - "POC-Master1"
  - "10.20.1.102"
  - "POC-Master2"
  - "10.20.1.103"
  - "POC-Worker0"
  - "10.20.1.104" 
  - "POC-Worker1"
  - "10.20.1.105" 
  - "POC-Worker2"
  - "10.20.1.106" 
  
# Identical network configuration
#cluster-cidr: "10.42.64.0/18"
#service-cidr: "10.42.0.0/18"
#cluster-dns: "10.42.0.10"

# Same backup and security settings
#profile: "cis-1.6"
selinux: true
secrets-encryption: true

# Node configuration
node-taint:
  - "CriticalAddonsOnly=true:NoExecute"
  
ingress-controller: none    
  
EOF

# 3. Avvia RKE2 server
sudo systemctl start rke2-server

curl -LO https://dl.k8s.io/release/v1.35.0/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

mkdir /root/.kube
cp /etc/rancher/rke2/rke2.yaml /root/.kube/config
