Compare commits
43 Commits
4da19c1500
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92effc8d42 | ||
|
|
55c736d55f | ||
|
|
fdc952020d | ||
|
|
e9773eacf2 | ||
|
|
fac09f2368 | ||
|
|
677e4d8827 | ||
|
|
31bfbbda77 | ||
|
|
937331e13a | ||
|
|
dbfd9f3053 | ||
|
|
748a4a03f7 | ||
|
|
3121598fec | ||
|
|
1e408cb79e | ||
|
|
abe437582f | ||
|
|
0713e5860a | ||
|
|
5e68ce5814 | ||
|
|
427ee381da | ||
|
|
6d31dc1584 | ||
|
|
0e723ee13f | ||
|
|
892a661dfc | ||
|
|
acc36cbdc7 | ||
|
|
e64d6525ed | ||
|
|
0da234dffd | ||
|
|
72d96550ce | ||
|
|
a4577bb70b | ||
|
|
6142bd0fad | ||
|
|
930f193a0c | ||
|
|
87ad42c701 | ||
|
|
4b7768a237 | ||
|
|
f6f9486efe | ||
|
|
ca0aad2e20 | ||
|
|
5c57b18121 | ||
|
|
82d32c3dbc | ||
|
|
1aa42a5e95 | ||
|
|
1f349aeeeb | ||
|
|
d8e64abba2 | ||
|
|
dbe9ea3dd2 | ||
|
|
abc2e585b0 | ||
|
|
d95892f269 | ||
|
|
438b220c73 | ||
|
|
27b2947950 | ||
|
|
7196849b2b | ||
|
|
d0e9cf2f29 | ||
|
|
f4163df97b |
25
README.md
25
README.md
@@ -1,2 +1,27 @@
|
|||||||
# infra_cloudinit
|
# infra_cloudinit
|
||||||
|
|
||||||
|
https://pabpereza.notion.site/Install-kubernetes-1-28-on-Ubuntu-Server-20-04-LTS-6f8d28eadb6242f0a78c40eaa0211167
|
||||||
|
|
||||||
|
https://medium.com/@pabloperezaradros/install-kubernetes-1-28-e42ad9194d4f
|
||||||
|
|
||||||
|
|
||||||
|
https://www.linuxtechi.com/install-kubernetes-on-ubuntu-24-04/
|
||||||
|
|
||||||
|
|
||||||
|
#Crea una plantilla desde la VM
|
||||||
|
|
||||||
|
PLANTILLA="919200"
|
||||||
|
qm template $PLANTILLA
|
||||||
|
|
||||||
|
|
||||||
|
# Ruta del archivo a modificar
|
||||||
|
CONFIG_FILE="/etc/dhcpcd.conf"
|
||||||
|
|
||||||
|
# Comentar la línea 'duid'
|
||||||
|
sed -i 's/^duid/#duid/' "$CONFIG_FILE"
|
||||||
|
|
||||||
|
# Descomentar la línea '#clientid'
|
||||||
|
sed -i 's/^#clientid/clientid/' "$CONFIG_FILE"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
32
clonar/0.crea_VM.sh
Executable file
32
clonar/0.crea_VM.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
# Crea variables
|
||||||
|
# ID de VM
|
||||||
|
VMID="920000"
|
||||||
|
|
||||||
|
# lugar de almacenamiento para el disco
|
||||||
|
### VMSTORAGE="VMs_storage-E"
|
||||||
|
VMSTORAGE="local"
|
||||||
|
|
||||||
|
# network
|
||||||
|
### VMNET="k8s"
|
||||||
|
VMNET="vmbr0"
|
||||||
|
|
||||||
|
# hostname
|
||||||
|
VMHOST="master"
|
||||||
|
|
||||||
|
# Genera la configuracion inicial de CLoudInit
|
||||||
|
./genera_yaml_k8s.sh
|
||||||
|
|
||||||
|
# apaga y borra la VM si existe antes
|
||||||
|
qm stop $VMID
|
||||||
|
qm destroy $VMID
|
||||||
|
|
||||||
|
qm create $VMID --name $VMHOST --memory 8192 --cores 4 --net0 virtio,bridge=$VMNET --cpu host --agent enabled=1 --tags clonar
|
||||||
|
qm set $VMID --ide2 VMs_storage-E:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0
|
||||||
|
|
||||||
|
# qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-server-cloudimg-amd64.img VMs_storage-E --format qcow2
|
||||||
|
qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-minimal-cloudimg-amd64.img local --format qcow2
|
||||||
|
qm set $VMID --scsihw virtio-scsi-pci --scsi0 $VMSTORAGE:$VMID/vm-$VMID-disk-0.qcow2
|
||||||
|
qm disk resize $VMID scsi0 40G
|
||||||
|
qm set $VMID --ipconfig0 ip=dhcp --cicustom "user=VMs_storage-E:snippets/user_data-clonar.yaml"
|
||||||
|
|
||||||
|
qm start $VMID
|
||||||
8
clonar/50-cloud-init.yaml
Normal file
8
clonar/50-cloud-init.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
network:
|
||||||
|
version: 2
|
||||||
|
ethernets:
|
||||||
|
eth0:
|
||||||
|
dhcp4: true
|
||||||
|
dhcp-identifier: mac
|
||||||
|
set-name: "eth0"
|
||||||
|
|
||||||
40
clonar/genera_yaml_k8s copy.sh
Executable file
40
clonar/genera_yaml_k8s copy.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Crea la base para la plantilla para kubernetes, borrando el machine-id y apagandola
|
||||||
|
# Despues usar qm template para convertirla
|
||||||
|
#
|
||||||
|
|
||||||
|
USER="curso"
|
||||||
|
PASSWORD="1"
|
||||||
|
PASSWORD_HASH=$(openssl passwd -6 "$PASSWORD")
|
||||||
|
PUB_KEY=$(cat ~/.ssh/id_rsa.pub)
|
||||||
|
VMHOST="k8scp"
|
||||||
|
|
||||||
|
cat <<EOF > /mnt/pve/VMs_storage-E/snippets/user_data-clonar.yaml
|
||||||
|
#cloud-config
|
||||||
|
|
||||||
|
system_info:
|
||||||
|
default_user:
|
||||||
|
name: $USER
|
||||||
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
|
shell: /bin/bash
|
||||||
|
lock_passwd: false
|
||||||
|
passwd: $PASSWORD_HASH
|
||||||
|
# passwd: \$6\$ogQI1CDWE.wdcMWI\$6kIrEjVBNC5.YxxFwBY9CxFGnIg1SDhndG4niMn5Sz11NNqay4icJS4AAddY6WbcM7LZJsLzwiYeUCLq2ddmL0
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- $PUB_KEY
|
||||||
|
ssh_pwauth: true
|
||||||
|
hostname: $VMHOST
|
||||||
|
manage_etc_hosts: true
|
||||||
|
fqdn: $VMHOST
|
||||||
|
runcmd:
|
||||||
|
- apt update && apt install git -y
|
||||||
|
- cd /root
|
||||||
|
- git clone https://git.lfgut.duckdns.org/luis/infra_cloudinit.git
|
||||||
|
- cd infra_cloudinit/clonar
|
||||||
|
- ./k8s.sh
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Archivo user_data.yaml creado con éxito."
|
||||||
|
|
||||||
|
|
||||||
41
clonar/genera_yaml_k8s.sh
Executable file
41
clonar/genera_yaml_k8s.sh
Executable file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Crea la base para la plantilla para kubernetes, borrando el machine-id y apagandola
|
||||||
|
# Despues usar qm template para convertirla
|
||||||
|
#
|
||||||
|
|
||||||
|
USER="curso"
|
||||||
|
PASSWORD="1"
|
||||||
|
PASSWORD_HASH=$(openssl passwd -6 "$PASSWORD")
|
||||||
|
PUB_KEY=$(cat ~/.ssh/id_rsa.pub)
|
||||||
|
VMHOST="k8scp"
|
||||||
|
|
||||||
|
cat <<EOF > /mnt/pve/VMs_storage-E/snippets/user_data-clonar.yaml
|
||||||
|
#cloud-config
|
||||||
|
|
||||||
|
system_info:
|
||||||
|
default_user:
|
||||||
|
name: $USER
|
||||||
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
|
shell: /bin/bash
|
||||||
|
lock_passwd: false
|
||||||
|
passwd: $PASSWORD_HASH
|
||||||
|
# passwd: \$6\$ogQI1CDWE.wdcMWI\$6kIrEjVBNC5.YxxFwBY9CxFGnIg1SDhndG4niMn5Sz11NNqay4icJS4AAddY6WbcM7LZJsLzwiYeUCLq2ddmL0
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- $PUB_KEY
|
||||||
|
ssh_pwauth: true
|
||||||
|
hostname: $VMHOST
|
||||||
|
manage_etc_hosts: true
|
||||||
|
fqdn: $VMHOST
|
||||||
|
# package_update: true
|
||||||
|
runcmd:
|
||||||
|
- apt update && apt install git -y
|
||||||
|
- cd /root
|
||||||
|
- git clone https://git.lfgut.duckdns.org/luis/infra_cloudinit.git
|
||||||
|
- cd infra_cloudinit/clonar
|
||||||
|
- ./k8s.sh
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Archivo user_data.yaml creado con éxito."
|
||||||
|
|
||||||
|
|
||||||
12
clonar/k8s.sh
Executable file
12
clonar/k8s.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cp 50-cloud-init.yaml /etc/netplan/
|
||||||
|
|
||||||
|
# Actualización del sistema
|
||||||
|
apt update
|
||||||
|
|
||||||
|
# Instalación del agente
|
||||||
|
apt install qemu-guest-agent -y
|
||||||
|
systemctl enable --now qemu-guest-agent
|
||||||
|
apt upgrade
|
||||||
|
reboot
|
||||||
19
docker/0.crea_VM.sh
Executable file
19
docker/0.crea_VM.sh
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
source config.sh
|
||||||
|
|
||||||
|
|
||||||
|
# Genera la configuracion inicial de CLoudInit
|
||||||
|
./genera_yaml_k8s.sh
|
||||||
|
|
||||||
|
# apaga y borra la VM si existe antes
|
||||||
|
qm stop $VMID
|
||||||
|
qm destroy $VMID
|
||||||
|
|
||||||
|
qm create $VMID --name $VMHOST --memory $VRAM --cores $VCORES --net0 virtio,bridge=$VMNET --cpu host --agent enabled=1 --tags docker
|
||||||
|
qm set $VMID --ide2 $VMSTORAGE:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0
|
||||||
|
|
||||||
|
qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-minimal-cloudimg-amd64.img $VMSTORAGE --format qcow2
|
||||||
|
qm set $VMID --scsihw virtio-scsi-pci --scsi0 $VMSTORAGE:$VMID/vm-$VMID-disk-0.qcow2
|
||||||
|
qm disk resize $VMID scsi0 40G
|
||||||
|
qm set $VMID --ipconfig0 ip=dhcp --cicustom "user=$VMSTORAGE:snippets/user_data-docker.yaml"
|
||||||
|
|
||||||
|
qm start $VMID
|
||||||
29
docker/1.instala_docker.sh
Executable file
29
docker/1.instala_docker.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
USER="curso" # Usuario con acceso sudo
|
||||||
|
|
||||||
|
# Actualizar sistema
|
||||||
|
echo "Actualizando el sistema..."
|
||||||
|
sudo apt-get update && sudo apt-get upgrade -y
|
||||||
|
|
||||||
|
|
||||||
|
# Add Docker's official GPG key:
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install ca-certificates curl
|
||||||
|
sudo install -m 0755 -d /etc/apt/keyrings
|
||||||
|
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
||||||
|
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
||||||
|
|
||||||
|
# Add the repository to Apt sources:
|
||||||
|
echo \
|
||||||
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
|
||||||
|
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
|
||||||
|
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
sudo apt-get update
|
||||||
|
|
||||||
|
|
||||||
|
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
|
||||||
|
|
||||||
|
# añade el usuario curso al grupo docker
|
||||||
|
usermod -aG docker $USER
|
||||||
8
docker/50-cloud-init.yaml
Normal file
8
docker/50-cloud-init.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
network:
|
||||||
|
version: 2
|
||||||
|
ethernets:
|
||||||
|
eth0:
|
||||||
|
dhcp4: true
|
||||||
|
dhcp-identifier: mac
|
||||||
|
set-name: "eth0"
|
||||||
|
|
||||||
32
docker/config.sh
Normal file
32
docker/config.sh
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# config.sh
|
||||||
|
|
||||||
|
# Crea variables
|
||||||
|
# ID de VM
|
||||||
|
VMID="930000"
|
||||||
|
|
||||||
|
# lugar de almacenamiento para el disco
|
||||||
|
VMSTORAGE="VMs_storage-E"
|
||||||
|
### VMSTORAGE="local"
|
||||||
|
|
||||||
|
# recursos
|
||||||
|
VRAM=4096
|
||||||
|
VCORES=2
|
||||||
|
|
||||||
|
|
||||||
|
# network
|
||||||
|
### VMNET="k8s"
|
||||||
|
VMNET="vmbr0"
|
||||||
|
|
||||||
|
# hostname
|
||||||
|
VMHOST="docker"
|
||||||
|
|
||||||
|
# usuario y password
|
||||||
|
USER="curso"
|
||||||
|
PASSWORD="1"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# calculos con lo que hay
|
||||||
|
|
||||||
|
PASSWORD_HASH=$(openssl passwd -6 "$PASSWORD")
|
||||||
|
PUB_KEY=$(cat ~/.ssh/id_rsa.pub)
|
||||||
37
docker/genera_yaml_k8s.sh
Executable file
37
docker/genera_yaml_k8s.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Crea la base para la plantilla para kubernetes, borrando el machine-id y apagandola
|
||||||
|
# Despues usar qm template para convertirla
|
||||||
|
#
|
||||||
|
|
||||||
|
source config.sh
|
||||||
|
|
||||||
|
cat <<EOF > /mnt/pve/VMs_storage-E/snippets/user_data-docker.yaml
|
||||||
|
#cloud-config
|
||||||
|
|
||||||
|
system_info:
|
||||||
|
default_user:
|
||||||
|
name: $USER
|
||||||
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
|
shell: /bin/bash
|
||||||
|
lock_passwd: false
|
||||||
|
passwd: $PASSWORD_HASH
|
||||||
|
# passwd: \$6\$ogQI1CDWE.wdcMWI\$6kIrEjVBNC5.YxxFwBY9CxFGnIg1SDhndG4niMn5Sz11NNqay4icJS4AAddY6WbcM7LZJsLzwiYeUCLq2ddmL0
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- $PUB_KEY
|
||||||
|
ssh_pwauth: true
|
||||||
|
hostname: $VMHOST
|
||||||
|
manage_etc_hosts: true
|
||||||
|
fqdn: $VMHOST
|
||||||
|
# package_update: true
|
||||||
|
runcmd:
|
||||||
|
- apt update && apt install git -y
|
||||||
|
- cd /root
|
||||||
|
- git clone https://git.lfgut.duckdns.org/luis/infra_cloudinit.git
|
||||||
|
- cd infra_cloudinit/docker
|
||||||
|
- ./k8s.sh
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Archivo user_data.yaml creado con éxito."
|
||||||
|
|
||||||
|
|
||||||
16
docker/k8s.sh
Executable file
16
docker/k8s.sh
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cp 50-cloud-init.yaml /etc/netplan/
|
||||||
|
|
||||||
|
# Actualización del sistema
|
||||||
|
apt update
|
||||||
|
|
||||||
|
# Instalación del agente
|
||||||
|
apt install qemu-guest-agent -y
|
||||||
|
systemctl enable --now qemu-guest-agent
|
||||||
|
apt upgrade -y
|
||||||
|
|
||||||
|
./1.instala_docker.sh
|
||||||
|
|
||||||
|
|
||||||
|
reboot
|
||||||
32
k8s/0.crea_VM.sh
Executable file
32
k8s/0.crea_VM.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
# Crea variables
|
||||||
|
# ID de VM
|
||||||
|
VMID="919200"
|
||||||
|
|
||||||
|
# lugar de almacenamiento para el disco
|
||||||
|
### VMSTORAGE="VMs_storage-E"
|
||||||
|
VMSTORAGE="local"
|
||||||
|
|
||||||
|
# network
|
||||||
|
### VMNET="k8s"
|
||||||
|
VMNET="vmbr0"
|
||||||
|
|
||||||
|
# hostname
|
||||||
|
VMHOST="k8scp"
|
||||||
|
|
||||||
|
# Genera la configuracion inicial de CLoudInit
|
||||||
|
./genera_yaml_k8s.sh
|
||||||
|
|
||||||
|
# apaga y borra la VM si existe antes
|
||||||
|
qm stop $VMID
|
||||||
|
qm destroy $VMID
|
||||||
|
|
||||||
|
qm create $VMID --name $VMHOST --memory 8192 --cores 4 --net0 virtio,bridge=$VMNET --cpu host --agent enabled=1 --tags k8s
|
||||||
|
qm set $VMID --ide2 VMs_storage-E:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0
|
||||||
|
|
||||||
|
# qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-server-cloudimg-amd64.img VMs_storage-E --format qcow2
|
||||||
|
qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-server-cloudimg-amd64.img local --format qcow2
|
||||||
|
qm set $VMID --scsihw virtio-scsi-pci --scsi0 $VMSTORAGE:$VMID/vm-$VMID-disk-0.qcow2
|
||||||
|
qm disk resize $VMID scsi0 40G
|
||||||
|
qm set $VMID --ipconfig0 ip=dhcp --cicustom "user=VMs_storage-E:snippets/user_data.yaml"
|
||||||
|
|
||||||
|
qm start $VMID
|
||||||
108
k8s/1.instala_kubernetes.sh
Executable file
108
k8s/1.instala_kubernetes.sh
Executable file
@@ -0,0 +1,108 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
USER="curso" # Usuario con acceso sudo
|
||||||
|
|
||||||
|
# Actualizar sistema
|
||||||
|
echo "Actualizando el sistema..."
|
||||||
|
sudo apt-get update && sudo apt-get upgrade -y
|
||||||
|
|
||||||
|
# Desactivar swap (requisito de Kubernetes)
|
||||||
|
## echo "Desactivando swap..."
|
||||||
|
## sudo swapoff -a
|
||||||
|
## sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
|
||||||
|
|
||||||
|
|
||||||
|
# Habilitar módulos necesarios para Kubernetes
|
||||||
|
echo "Habilitando módulos del kernel..."
|
||||||
|
sudo modprobe overlay
|
||||||
|
sudo modprobe br_netfilter
|
||||||
|
|
||||||
|
|
||||||
|
# Configure persistent loading of modules
|
||||||
|
# sudo tee /etc/modules-load.d/k8s.conf <<EOF
|
||||||
|
sudo tee /etc/modules-load.d/containerd.conf <<EOF
|
||||||
|
overlay
|
||||||
|
br_netfilter
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Requisitos para Kubernetes
|
||||||
|
cat <<EOF | sudo tee /etc/sysctl.d/kubernetes.conf
|
||||||
|
net.bridge.bridge-nf-call-ip6tables = 1
|
||||||
|
net.bridge.bridge-nf-call-iptables = 1
|
||||||
|
net.ipv4.ip_forward = 1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sudo sysctl --system
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Install required packages
|
||||||
|
sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y
|
||||||
|
|
||||||
|
|
||||||
|
# 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" -y
|
||||||
|
|
||||||
|
# Install containerd
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install containerd.io -y
|
||||||
|
|
||||||
|
# Configure containerd and start service
|
||||||
|
# sudo mkdir -p /etc/containerd
|
||||||
|
sudo containerd config default|sudo tee /etc/containerd/config.toml >/dev/null 2>&1
|
||||||
|
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
|
||||||
|
sudo sed -i 's/pause:3.8/pause:3.10/g' /etc/containerd/config.toml
|
||||||
|
|
||||||
|
# restart containerd
|
||||||
|
sudo systemctl restart containerd
|
||||||
|
# sudo systemctl enable containerd
|
||||||
|
# systemctl status containerd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Configurar el repositorio de Kubernetes
|
||||||
|
echo "Agregando el repositorio de Kubernetes..."
|
||||||
|
### sudo apt-get install apt-transport-https ca-certificates curl -y
|
||||||
|
# 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.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/k8s.gpg
|
||||||
|
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/k8s.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/k8s.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 kubelet kubeadm kubectl -y
|
||||||
|
sudo apt-mark hold kubelet kubeadm kubectl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Instalar containerd
|
||||||
|
#echo "Instalando containerd..."
|
||||||
|
# sudo apt-get install -y containerd
|
||||||
|
# sudo mkdir -p /etc/containerd
|
||||||
|
# containerd config default | sudo tee /etc/containerd/config.toml
|
||||||
|
|
||||||
|
# Configurar containerd para usar systemd como driver de cgroup
|
||||||
|
# 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
|
||||||
|
|
||||||
22
k8s/2.levanta_cluster.sh
Executable file
22
k8s/2.levanta_cluster.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
USER="curso" # Usuario con acceso sudo
|
||||||
|
|
||||||
|
sudo kubeadm config images pull
|
||||||
|
|
||||||
|
echo "Inicializando el nodo maestro..."
|
||||||
|
sudo kubeadm init --control-plane-endpoint=k8s01 --upload-certs --pod-network-cidr=172.24.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..."
|
||||||
|
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
|
||||||
|
|
||||||
|
# eliminar restriccion de pods en el master
|
||||||
|
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
|
||||||
|
|
||||||
31
k8s/3.instala_calico.sh
Executable file
31
k8s/3.instala_calico.sh
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# instala con operator -ok-
|
||||||
|
|
||||||
|
curl -O 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 -i 's/192.168.0.0/172.24.0.0/g' custom-resources.yaml
|
||||||
|
|
||||||
|
|
||||||
|
kubectl create -f tigera-operator.yaml
|
||||||
|
kubectl create -f custom-resources.yaml
|
||||||
|
|
||||||
|
|
||||||
|
kubectl get pods -A
|
||||||
|
|
||||||
|
|
||||||
|
### kubectl get pods -A -w
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## instala con manifest -deprecated-
|
||||||
|
|
||||||
|
# kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/calico.yaml
|
||||||
|
|
||||||
|
#### wget https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/calico.yaml
|
||||||
|
#### sed -ie 's/192.168.0.0/172.24.0.0/g' calico.yaml
|
||||||
|
|
||||||
|
|
||||||
34
k8s/4.prueba_k8s.sh
Executable file
34
k8s/4.prueba_k8s.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
|
||||||
|
kubectl create ns demo-app
|
||||||
|
kubectl create deployment nginx-app --image nginx --replicas 2 --namespace demo-app
|
||||||
|
kubectl get deployment -n demo-app
|
||||||
|
kubectl get pods -n demo-app
|
||||||
|
|
||||||
|
kubectl scale --replicas=20 deployment nginx-app -n demo-app
|
||||||
|
|
||||||
|
kubectl delete deployment nginx-app -n demo-app
|
||||||
|
|
||||||
|
kubectl expose deployment nginx-app -n demo-app --type NodePort --port 80
|
||||||
|
kubectl get svc -n demo-app
|
||||||
|
|
||||||
|
# poner la IP obtenida
|
||||||
|
#### curl http://<Any-worker-IP>:<puerto>
|
||||||
|
|
||||||
|
curl http://localhost:30336
|
||||||
|
|
||||||
|
|
||||||
|
kubectl create ns demo-app
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kubectl run test-pod2 --image=busybox -- sleep 3600
|
||||||
|
|
||||||
|
kubectl create deployment gitea-app2 --image gitea/gitea:latest --replicas 2 --namespace demo-app
|
||||||
|
|
||||||
|
kubectl describe pod nginx-app --namespace demo-app | less
|
||||||
|
|
||||||
|
kubectl delete deployment gitea-app --namespace demo-app
|
||||||
7
k8s/5.autocomplete_in_bash.sh
Executable file
7
k8s/5.autocomplete_in_bash.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo 'source <(kubectl completion bash)' >>~/.bashrc
|
||||||
|
|
||||||
|
# Reload sourcefile again (located on home)
|
||||||
|
source .bashrc
|
||||||
|
|
||||||
15
k8s/6.borra_cluster.sh
Executable file
15
k8s/6.borra_cluster.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
|
||||||
|
sudo kubeadm reset -f
|
||||||
|
|
||||||
|
sudo rm -rf /etc/cni/net.d
|
||||||
|
|
||||||
|
sudo ip link show | grep cni
|
||||||
|
sudo ip link delete <nombre-del-bridge>
|
||||||
|
|
||||||
|
sudo rm -rf /var/lib/kubelet /var/lib/dockershim /var/lib/etcd /var/lib/cni
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
33
k8s/add-nodo.md
Normal file
33
k8s/add-nodo.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
Your Kubernetes control-plane has initialized successfully!
|
||||||
|
|
||||||
|
To start using your cluster, you need to run the following as a regular user:
|
||||||
|
|
||||||
|
mkdir -p $HOME/.kube
|
||||||
|
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
|
||||||
|
sudo chown $(id -u):$(id -g) $HOME/.kube/config
|
||||||
|
|
||||||
|
Alternatively, if you are the root user, you can run:
|
||||||
|
|
||||||
|
export KUBECONFIG=/etc/kubernetes/admin.conf
|
||||||
|
|
||||||
|
You should now deploy a pod network to the cluster.
|
||||||
|
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
|
||||||
|
https://kubernetes.io/docs/concepts/cluster-administration/addons/
|
||||||
|
|
||||||
|
You can now join any number of control-plane nodes running the following command on each as root:
|
||||||
|
|
||||||
|
kubeadm join k8s01:6443 --token mlv46u.o92gie7d9wseptfx \
|
||||||
|
--discovery-token-ca-cert-hash sha256:2c20f2d546d59772bb0a82fae16c213c8c7a35b80365f39cd6e5be037f84a94a \
|
||||||
|
--control-plane --certificate-key 8985eb6d3979f371b7c2dbd98e14f071fe7fd1a86468112d501c29ffe7e6843e
|
||||||
|
|
||||||
|
Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
|
||||||
|
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
|
||||||
|
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.
|
||||||
|
|
||||||
|
Then you can join any number of worker nodes by running the following on each as root:
|
||||||
|
|
||||||
|
kubeadm join k8s01:6443 --token mlv46u.o92gie7d9wseptfx \
|
||||||
|
--discovery-token-ca-cert-hash sha256:2c20f2d546d59772bb0a82fae16c213c8c7a35b80365f39cd6e5be037f84a94a
|
||||||
|
|
||||||
|
|
||||||
37
k8s/crea_VM copy.sh
Executable file
37
k8s/crea_VM copy.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
# Crea variables
|
||||||
|
# ID de VM
|
||||||
|
VMID="919200"
|
||||||
|
|
||||||
|
# lugar de almacenamiento para el disco
|
||||||
|
### VMSTORAGE="VMs_storage-E"
|
||||||
|
VMSTORAGE="local"
|
||||||
|
|
||||||
|
# network
|
||||||
|
### VMNET="k8s"
|
||||||
|
VMNET="vmbr0"
|
||||||
|
|
||||||
|
# Genera la configuracion inicial de CLoudInit
|
||||||
|
./genera_yaml_k8s.sh
|
||||||
|
|
||||||
|
# apaga y borra la VM si existe antes
|
||||||
|
qm stop $VMID
|
||||||
|
qm destroy $VMID
|
||||||
|
|
||||||
|
qm create $VMID --name ubuntu-cloud --memory 2048 --cores 2 --net0 virtio,bridge=$VMNET --cpu host --agent enabled=1 --tags k8s
|
||||||
|
|
||||||
|
# qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-server-cloudimg-amd64.img VMs_storage-E --format qcow2
|
||||||
|
qm importdisk $VMID /mnt/pve/ISOs_storage/template/iso/ubuntu-24.04-server-cloudimg-amd64.img local --format qcow2
|
||||||
|
|
||||||
|
qm set $VMID --scsihw virtio-scsi-pci --scsi0 $VMSTORAGE:$VMID/vm-$VMID-disk-0.qcow2
|
||||||
|
|
||||||
|
qm set $VMID --ide2 VMs_storage-E:cloudinit
|
||||||
|
qm set $VMID --boot c --bootdisk scsi0
|
||||||
|
qm set $VMID --serial0 socket --vga serial0
|
||||||
|
|
||||||
|
qm disk resize $VMID scsi0 10G
|
||||||
|
|
||||||
|
qm set $VMID --ipconfig0 ip=dhcp
|
||||||
|
|
||||||
|
qm set $VMID --cicustom "user=VMs_storage-E:snippets/user_data.yaml"
|
||||||
|
|
||||||
|
qm start $VMID
|
||||||
@@ -8,6 +8,7 @@ USER="curso"
|
|||||||
PASSWORD="1"
|
PASSWORD="1"
|
||||||
PASSWORD_HASH=$(openssl passwd -6 "$PASSWORD")
|
PASSWORD_HASH=$(openssl passwd -6 "$PASSWORD")
|
||||||
PUB_KEY=$(cat ~/.ssh/id_rsa.pub)
|
PUB_KEY=$(cat ~/.ssh/id_rsa.pub)
|
||||||
|
VMHOST="k8scp"
|
||||||
|
|
||||||
cat <<EOF > /mnt/pve/VMs_storage-E/snippets/user_data.yaml
|
cat <<EOF > /mnt/pve/VMs_storage-E/snippets/user_data.yaml
|
||||||
#cloud-config
|
#cloud-config
|
||||||
@@ -23,9 +24,9 @@ system_info:
|
|||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- $PUB_KEY
|
- $PUB_KEY
|
||||||
ssh_pwauth: true
|
ssh_pwauth: true
|
||||||
hostname: ubuntu-cloud
|
hostname: $VMHOST
|
||||||
manage_etc_hosts: true
|
manage_etc_hosts: true
|
||||||
fqdn: ubuntu-cloud
|
fqdn: $VMHOST
|
||||||
runcmd:
|
runcmd:
|
||||||
- cd /root
|
- cd /root
|
||||||
- git clone https://git.lfgut.duckdns.org/luis/infra_cloudinit.git
|
- git clone https://git.lfgut.duckdns.org/luis/infra_cloudinit.git
|
||||||
37
k8s/k8s copy.sh
Executable file
37
k8s/k8s copy.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# Actualización del sistema
|
||||||
|
apt update && apt upgrade -y
|
||||||
|
|
||||||
|
# Instalación de dependencias necesarias
|
||||||
|
apt install qemu-guest-agent apt-transport-https ca-certificates curl software-properties-common -y
|
||||||
|
systemctl enable --now qemu-guest-agent
|
||||||
|
|
||||||
|
# https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
|
||||||
|
# version 1.32
|
||||||
|
|
||||||
|
# Agregar la clave de Google Cloud
|
||||||
|
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
|
||||||
|
|
||||||
|
|
||||||
|
# Agregar el repositorio de Kubernetes
|
||||||
|
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
|
||||||
|
|
||||||
|
|
||||||
|
# Actualizar los repositorios e instalar Kubernetes
|
||||||
|
apt update
|
||||||
|
apt install kubelet kubeadm kubectl -y
|
||||||
|
|
||||||
|
# Marcar los paquetes para que no se actualicen
|
||||||
|
apt-mark hold kubelet kubeadm kubectl
|
||||||
|
|
||||||
|
# Habilitar el servicio kubelet
|
||||||
|
sudo systemctl enable kubelet && sudo systemctl start kubelet
|
||||||
|
|
||||||
|
# Instalar herramientas de red para el cluster (Flannel como ejemplo)
|
||||||
|
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
|
||||||
|
|
||||||
|
# Reiniciar para aplicar cambios
|
||||||
|
sudo reboot
|
||||||
|
|
||||||
9
k8s/k8s.sh
Executable file
9
k8s/k8s.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# Actualización del sistema
|
||||||
|
apt update && apt upgrade -y
|
||||||
|
|
||||||
|
# Instalación de dependencias necesarias
|
||||||
|
apt install qemu-guest-agent -y
|
||||||
|
systemctl enable --now qemu-guest-agent
|
||||||
Reference in New Issue
Block a user