prueba 002

This commit is contained in:
trigkeyb
2025-01-09 21:01:53 +01:00
parent dbe9ea3dd2
commit d8e64abba2
2 changed files with 64 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# Variables
KUBERNETES_VERSION="1.28.2-00" # Cambia por la versión que necesites
#KUBERNETES_VERSION="1.28.2-00" # Cambia por la versión que necesites
USER="curso" # Usuario con acceso sudo
# Actualizar sistema
@@ -16,19 +16,60 @@ sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# Configurar el repositorio de Kubernetes
echo "Agregando el repositorio de Kubernetes..."
sudo apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
# If the folder `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg # allow unprivileged APT programs to read this keyring
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list # helps tools such as command-not-found to work correctly
#curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
#echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
# Instalar Kubernetes
echo "Instalando Kubernetes (kubeadm, kubelet, kubectl)..."
sudo apt-get update
sudo apt-get install -y kubelet=$KUBERNETES_VERSION kubeadm=$KUBERNETES_VERSION kubectl=$KUBERNETES_VERSION
#sudo apt-get install -y kubelet=$KUBERNETES_VERSION kubeadm=$KUBERNETES_VERSION kubectl=$KUBERNETES_VERSION
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
# Habilitar módulos necesarios para Kubernetes
echo "Habilitando módulos del kernel..."
sudo modprobe overlay
sudo modprobe br_netfilter
sudo modprobe br_netfilters
# Configure persistent loading of modules
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
# Install required packages
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
# Add Docker repo
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Install containerd
sudo apt update
sudo apt install -y containerd.io
# Configure containerd and start service
sudo mkdir -p /etc/containerd
sudo containerd config default|sudo tee /etc/containerd/config.toml
# restart containerd
sudo systemctl restart containerd
sudo systemctl enable containerd
systemctl status containerd
cat <<EOF | sudo tee /etc/sysctl.d/kubernetes.conf
net.bridge.bridge-nf-call-ip6tables = 1
@@ -48,3 +89,6 @@ containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd
sudo kubeadm config images pull

View File

@@ -1,14 +1,13 @@
#!/bin/bash
# Variables
KUBERNETES_VERSION="1.28.2-00" # Cambia por la versión que necesites
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=192.168.0.0/16
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..."
@@ -18,7 +17,20 @@ if [ "$INIT_MASTER" == "y" ]; then
# Instalar red de pods (Calico)
echo "Instalando la red de pods (Calico)..."
kubectl apply -f https://docs.projectcalico.org/v3.25/manifests/calico.yaml
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