Saltar al contenido
Kubernetes

Kubernetes

Kubernetes es un sistema de orquestación de contenedores creado por Google.
Al igual que existen múltiples distribuciones de Linux, existen múltiples distribuciones de Kubernetes.
K3s es una distribución Kubernetes ligera creada por Rancher.

Todos estos proyectos están gestionados hoy en día por la Cloud Native Computing Foundation.

Instalación de herramientas

k3sup es una herramienta de línea de comandos para desplegar un clúster K3s en una o varias máquinas.
La instalaremos con pkgx.
~/tp $ yq -i e '.dependencies["github.com/alexellis/k3sup"]="^0.13.1"' pkgx.yaml
~/tp $ yq '.dependencies["github.com/alexellis/k3sup"]' pkgx.yaml
^0.13.1

Despliegue de un clúster k3s

~/tp $ cat <<'EOS' > deploy-k3s.bash
#!/bin/bash

declare -r BOOTSTRAP_IP="$(terraform output -raw bootstrap_ip)"
declare -r BOOTSTRAP_USER="$(terraform output -raw bootstrap_user)"
declare -a COMPUTE_IP=($(terraform output -json | jq -j '.compute_ip.value|join(" ")'))
declare -a COMPUTE_USER=($(terraform output -json | jq -j '.compute_user.value|join(" ")'))

k3sup install \
    --cluster \
    --host "${BOOTSTRAP_IP}" \
    --user "${BOOTSTRAP_USER}" \
    --k3s-channel stable

ssh -l ${BOOTSTRAP_USER} ${BOOTSTRAP_IP} <<'EOF'
curl -fsS https://pkgx.sh |sh
eval "$(pkgx integrate)"

mkdir -p work
cat <<EOT > work/pkgx.yaml
dependencies:
  jq: ^1.7
  helm.sh: ^3.12.3
  k9s: ^0.27.4
  gnu.org/coreutils: ^9.4.0
EOT
cd work
dev
EOF

for i in ${!COMPUTE_IP[@]}; do \
    k3sup join \
        --server-host "${BOOTSTRAP_IP}" \
        --server-user "${BOOTSTRAP_USER}" \
        --host "${COMPUTE_IP[$i]}" \
        --user "${COMPUTE_USER[$i]}" \
        --k3s-channel stable
done
EOS
~/tp $ bash deploy-k3s.bash