diff --git a/clonar/k8s.sh b/clonar/k8s.sh index af48d24..ea81947 100755 --- a/clonar/k8s.sh +++ b/clonar/k8s.sh @@ -8,5 +8,5 @@ apt update # Instalación del agente apt install qemu-guest-agent -y systemctl enable --now qemu-guest-agent -apt upgrade -y +apt upgrade reboot diff --git a/ubuntu_docker/0.crea_VM.sh b/ubuntu_docker/0.crea_VM.sh new file mode 100755 index 0000000..6068ff2 --- /dev/null +++ b/ubuntu_docker/0.crea_VM.sh @@ -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="docker" + +# 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-docker.yaml" + +qm start $VMID diff --git a/ubuntu_docker/1.instala_docker.sh b/ubuntu_docker/1.instala_docker.sh new file mode 100755 index 0000000..56997e8 --- /dev/null +++ b/ubuntu_docker/1.instala_docker.sh @@ -0,0 +1,28 @@ +#!/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 + + diff --git a/ubuntu_docker/50-cloud-init.yaml b/ubuntu_docker/50-cloud-init.yaml new file mode 100644 index 0000000..5f71f2c --- /dev/null +++ b/ubuntu_docker/50-cloud-init.yaml @@ -0,0 +1,8 @@ +network: + version: 2 + ethernets: + eth0: + dhcp4: true + dhcp-identifier: mac + set-name: "eth0" + \ No newline at end of file diff --git a/ubuntu_docker/genera_yaml_k8s.sh b/ubuntu_docker/genera_yaml_k8s.sh new file mode 100755 index 0000000..f6c1dd7 --- /dev/null +++ b/ubuntu_docker/genera_yaml_k8s.sh @@ -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="docker" + +cat < /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." + + diff --git a/ubuntu_docker/k8s.sh b/ubuntu_docker/k8s.sh new file mode 100755 index 0000000..ea81947 --- /dev/null +++ b/ubuntu_docker/k8s.sh @@ -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