Added install of kubectl, rancher and new dedicated preseed for kubernetes

master
Meliurwen 4 years ago
parent 360310b779
commit 6b7a908e50
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 0
      NOTES.md
  2. 12
      custom/disable_swap.sh
  3. 12
      custom/generate_ssh_cluster.sh
  4. 18
      custom/install_base_packages.sh
  5. 2
      custom/install_docker-compose.sh
  6. 4
      custom/install_docker.sh
  7. 59
      custom/install_kubectl.sh
  8. 19
      custom/install_rancher.sh
  9. 6
      custom/main.sh
  10. 100
      preseed/kube.cfg
  11. 4
      preseed/preseed.cfg

@ -0,0 +1,12 @@
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
echo "Disabling swap..."
swapoff -a
echo "Disabling swap permanently ('/etc/fstab.bak' created)..."
sed -i.bak '/ swap /d' /etc/fstab

@ -0,0 +1,12 @@
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
echo "Creating SSH key..."
ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa
echo "Adding SSH key to authorized..."
cat ~/.ssh/rsa.pub >> ~/.ssh/authorized_keys

@ -1,11 +1,23 @@
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
apt-get update
echo "Updating apt package index..."
apt-get update > /dev/null
apt-get install software-properties-common python3-pip
apt -q -y upgrade
apt-get autoremove --purge
echo "Installing base packages..."
apt-get -q -y -o Dpkg::Use-Pty=0 install \
nano \
htop \
nload \
nethogs
echo "Cleaning apt cache..."
apt-get clean

@ -2,7 +2,7 @@
set -eu
if [ $(id -u) -ne 0 ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi

@ -2,7 +2,7 @@
set -eu
if [ $(id -u) -ne 0 ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
@ -11,7 +11,7 @@ SUPPORTED_ARCH="amd64 armhf arm64"
ARCH=$(dpkg --print-architecture)
echo "Checking system architecture..."
if echo $SUPPORTED_ARCH | grep -w $ARCH > /dev/null; then
if echo "${SUPPORTED_ARCH}" | grep -w "${ARCH}" > /dev/null; then
echo "Architecture ${ARCH} supported."
else
echo "Architecture ${ARCH} not supported! Aborting..."

@ -0,0 +1,59 @@
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
#
# Following this guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/
#
echo "Updating apt package index..."
apt-get update > /dev/null
echo "Installing prerequisites..."
apt-get -q -y -o Dpkg::Use-Pty=0 install apt-transport-https gnupg2 curl
echo "Adding Kubernetes' repo key..."
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "Adding Kubernetes repo..."
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
echo "Updating apt package index again..."
apt-get update > /dev/null
echo "Installing 'kubectl'..."
apt-get -q -y -o Dpkg::Use-Pty=0 install kubectl
# TODO: the command `kubectl cluster-info` gives an error and the script
# provided from the docs gives an error. In the docs they are make
# some sort of assumption that I cannot still figure out.
# Ffs this is an entry level doc and they already start to omit not
# obvious stuff... sorry for not owning a magic crystal ball. >:(
# THIS, is a quality doc:
# https://www.valent-blog.eu/2019/01/01/installare-kubernetes-in-debian-9/
# The lines below comes from this doc.
echo "Installing 'kubelet' and 'kubeadm'..."
apt-get -q -y -o Dpkg::Use-Pty=0 install kubelet kubeadm
echo "Marking in hold the packages 'kubectl', 'kubelet' and 'kubeadm' in order to prevent them to update in the future..."
apt-mark hold kubelet kubeadm kubectl
echo "Reloading systemd and restarting 'kubelet' service"
systemctl daemon-reload
systemctl restart kubelet
# I guess these are the base images of kubernetes (?)
echo "Pulling some base images.."
kubeadm config images pull
echo "Initializing kuvernetes.."
kubeadm init
echo "Adding kubernetes config to this user home folder (useful for non-root users)..."
mkdir -p "$HOME/.kube"
cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config"
chown "$(id -u)":"$(id -g)" "$HOME/.kube/config"

@ -0,0 +1,19 @@
#!/bin/sh
# Sources:
# https://www.rancher.cn/an-introduction-to-rke
# https://devopsheaven.com/kubernetes/k8s/rke/devops/deploy/2019/10/21/install-kubernetes-locally-rke.html
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
echo "Downloading and installing 'rke' executable..."
wget -O rke https://github.com/rancher/rke/releases/download/v1.2.3/rke_linux-amd64 && \
chmod +x rke && \
mv rke /usr/local/bin && \
rke --version
echo "Giving access to the docker socket at the SSH user..."
usermod -aG docker "$(id -un)"

@ -1,6 +1,6 @@
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "This script should be run as root. Aborting..." > /dev/stderr
exit 1
fi
@ -10,5 +10,9 @@ SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
eval "${SCRIPTPATH}/install_packages.sh"
eval "${SCRIPTPATH}/install_docker.sh"
eval "${SCRIPTPATH}/install_docker-compose.sh"
eval "${SCRIPTPATH}/disable_swap.sh"
eval "${SCRIPTPATH}/install_kubectl.sh"
eval "${SCRIPTPATH}/install_rancher.sh"
eval "${SCRIPTPATH}/generate_ssh_cluster.sh"
apt-get clean

@ -0,0 +1,100 @@
#_preseed_V1
#### Contents of the preconfiguration file (for buster)
### Localization
d-i debian-installer/language string it
d-i debian-installer/country string IT
d-i debian-installer/locale string it_IT.UTF-8
# Keyboard selection.
# Usare Ctrl+Alt+Backspace per terminare il server X?
d-i keyboard-configuration/ctrl_alt_bksp boolean true
d-i keyboard-configuration/modelcode string pc105
d-i keyboard-configuration/toggle select No toggling
d-i keyboard-configuration/altgr select The default for the keyboard layout
d-i keyboard-configuration/layoutcode string it
d-i keyboard-configuration/variant select Italiana
d-i keyboard-configuration/compose select No compose key
d-i keyboard-configuration/switch select No temporary switch
d-i console-setup/variantcode string qwerty
d-i keyboard-configuration/model select Generic 105-key PC (intl.)
d-i keyboard-configuration/xkb-keymap select it
d-i keyboard-configuration/unsupported_config_options boolean true
d-i keyboard-configuration/unsupported_config_layout boolean true
d-i keyboard-configuration/unsupported_layout boolean true
d-i keyboard-configuration/unsupported_options boolean true
### Network configuration
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string debian-test
d-i netcfg/get_domain string dominio-test
d-i netcfg/wireless_wep string
d-i hw-detect/load_firmware boolean true
### Mirror settings
d-i mirror/country string manual
d-i mirror/http/hostname string debian.mirror.garr.it
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
### Account setup
# Skip creation of a root account (normal user account will be able to
# use sudo).
d-i passwd/root-login boolean false
d-i passwd/user-fullname string Virtualuser
d-i passwd/username string virtualuser
d-i passwd/user-password-crypted password $6$SmihMODnNymjr40/$YAkRABY.qE8tOjXmg0Z6X5e.mdLOUsUseNaPwaLyCjK17LzV/NLE3IfcmkQgwGjBeeQ7peGEfurqe.SBY7JHU1
### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i time/zone string Europe/Rome
d-i clock-setup/ntp boolean true
### Partitioning
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/expert_recipe string \
root :: \
4096 100 -1 ext4 \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ / } \
.
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/mount_style select uuid
d-i partman-basicfilesystems/no_swap boolean false
### Apt setup
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
### Package selection
tasksel tasksel/first multiselect none
# Individual additional packages to install
# Note: "console-setup" and "keyboard-configuration" are foundamental for
# keyboard configuration
d-i pkgsel/include string nano wget openssh-server console-setup keyboard-configuration
popularity-contest popularity-contest/participate boolean false
### Boot loader installation
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda
### Finishing up the installation
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/poweroff boolean true
#### Advanced options
d-i preseed/late_command string modprobe usb-storage isofs; mkdir -p /cdrom; mount /dev/cdrom /cdrom; cp -r /cdrom/custom /target/srv/custom

@ -146,8 +146,8 @@ d-i passwd/root-login boolean false
#d-i passwd/root-password-crypted password [crypt(3) hash]
# To create a normal user account.
d-i passwd/user-fullname string Meli
d-i passwd/username string meli
d-i passwd/user-fullname string Virtualuser
d-i passwd/username string virtualuser
# Normal user's password, either in clear text
#d-i passwd/user-password password insecure
#d-i passwd/user-password-again password insecure

Loading…
Cancel
Save