Compare commits
22 Commits
| 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 |
16
README.md
16
README.md
@@ -8,4 +8,20 @@ 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
|
||||
@@ -61,6 +61,11 @@ 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
|
||||
@@ -99,5 +104,5 @@ sudo apt-mark hold kubelet kubeadm kubectl
|
||||
# sudo systemctl restart containerd
|
||||
# sudo systemctl enable containerd
|
||||
|
||||
sudo kubeadm config images pull
|
||||
#sudo kubeadm config images pull
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
# Variables
|
||||
USER="curso" # Usuario con acceso sudo
|
||||
|
||||
|
||||
sudo kubeadm config images pull
|
||||
|
||||
echo "Inicializando el nodo maestro..."
|
||||
sudo kubeadm init --control-plane-endpoint=k8scp --upload-certs --pod-network-cidr=172.24.0.0/16
|
||||
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
|
||||
@@ -7,6 +7,9 @@ kubectl create deployment nginx-app --image nginx --replicas 2 --namespace demo-
|
||||
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
|
||||
@@ -17,6 +20,8 @@ kubectl get svc -n demo-app
|
||||
curl http://localhost:30336
|
||||
|
||||
|
||||
kubectl create ns demo-app
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user