empezando con docker
This commit is contained in:
32
ubuntu_docker/0.crea_VM.sh
Executable file
32
ubuntu_docker/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="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
|
||||
28
ubuntu_docker/1.instala_docker.sh
Executable file
28
ubuntu_docker/1.instala_docker.sh
Executable file
@@ -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
|
||||
|
||||
|
||||
8
ubuntu_docker/50-cloud-init.yaml
Normal file
8
ubuntu_docker/50-cloud-init.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
eth0:
|
||||
dhcp4: true
|
||||
dhcp-identifier: mac
|
||||
set-name: "eth0"
|
||||
|
||||
41
ubuntu_docker/genera_yaml_k8s.sh
Executable file
41
ubuntu_docker/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="docker"
|
||||
|
||||
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."
|
||||
|
||||
|
||||
12
ubuntu_docker/k8s.sh
Executable file
12
ubuntu_docker/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
|
||||
Reference in New Issue
Block a user