compacta la creacion de la VM

This commit is contained in:
trigkeyb
2025-01-09 18:14:30 +01:00
parent d0e9cf2f29
commit 7196849b2b
4 changed files with 100 additions and 12 deletions

37
crea_VM copy.sh Executable file
View 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

View File

@@ -18,20 +18,12 @@ 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 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 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 set $VMID --ipconfig0 ip=dhcp --cicustom "user=VMs_storage-E:snippets/user_data.yaml"
qm start $VMID

View File

@@ -30,7 +30,7 @@ runcmd:
- cd /root
- git clone https://git.lfgut.duckdns.org/luis/infra_cloudinit.git
- cd infra_cloudinit
- ./k8s.sh
# - ./k8s.sh
EOF
echo "Archivo user_data.yaml creado con éxito."

59
k8s_001.sh Executable file
View File

@@ -0,0 +1,59 @@
apt update
apt upgrade -y
apt install apt-transport-https qemu-guest-agent -y
systemctl enable --now qemu-guest-agent
# https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
# version 1.32
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg
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
chmod 644 /etc/apt/sources.list.d/kubernetes.list
apt update
apt install kubelet kubeadm kubectl -y
apt-mark hold kubelet kubeadm kubectl
# Enable kernel modules
modprobe overlay
modprobe br_netfilter
# Add some settings to sysctl
tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
# Reload sysctl
sysctl --system
# Configure persistent loading of modules
tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
# Install required packages
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
add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Install containerd
apt update
DEBIAN_FRONTEND=noninteractive apt install -y containerd.io
# Configure containerd and start service
mkdir -p /etc/containerd
containerd config default|sudo tee /etc/containerd/config.toml
# restart containerd
systemctl restart containerd
systemctl enable containerd
systemctl status containerd