Files
infra_cloudinit/levanta_cluster.sh
2025-01-09 21:01:53 +01:00

39 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Variables
USER="curso" # Usuario con acceso sudo
# Inicializar el nodo maestro (opcional)
read -p "¿Quieres inicializar el nodo maestro ahora? (y/n): " INIT_MASTER
if [ "$INIT_MASTER" == "y" ]; then
echo "Inicializando el nodo maestro..."
sudo kubeadm init --pod-network-cidr=174.24.0.0/16 --cri-socket=unix:///run/containerd/containerd.sock --upload-certs --control-plane-endpoint=k8scp
# Configurar kubectl para el usuario
echo "Configurando kubectl para el usuario $USER..."
mkdir -p /home/$USER/.kube
sudo cp -i /etc/kubernetes/admin.conf /home/$USER/.kube/config
sudo chown $(id -u $USER):$(id -g $USER) /home/$USER/.kube/config
# Instalar red de pods (Calico)
echo "Instalando la red de pods (Calico)..."
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/tigera-operator.yaml
curl -O https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/custom-resources.yaml
sed -ie 's/192.168.0.0/172.24.0.0/g' custom-resources.yaml
kubectl create -f custom-resources.yaml
# curl -O https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml
# curl -O https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml
# kubectl create -f tigera-operator.yaml
# kubectl apply -f https://docs.projectcalico.org/v3.25/manifests/calico.yaml
## kubectl get pods --all-namespaces -w
else
echo "Nodo maestro no inicializado. Ejecuta 'kubeadm init' manualmente si deseas configurarlo más tarde."
fi
echo "Instalación de Kubernetes completada."