Skip to content

Conteneurs > Orchestration > Kubernetes

Tip

Kubernetes est un système d'orchestration de conteneurs créé par Google. De même qu'il existe plusieurs distributions Linux, il existe plusieurs distributions Kubernetes.
K3s est une distribution Kubernetes légère créée par la société Rancher.

L'ensemble de ces projets est aujourd'hui géré par la Cloud Native Computing Foundation.

Installation des outils

Tip

k3sup est une commande permettant de déployer un cluster K3s sur une ou plusieurs machines.
Nous allons l'installer avec 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

Déploiment d'un cluster k3s

~/tp $ cat <<'EOS' > deploy-k3s.bssh
#!/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

# Join compute
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