#!/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 kubernetes.." 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" # This last one thanks to: # https://stackoverflow.com/questions/53814150/how-to-setup-a-2-node-kubernetes-cluster-in-custom-environment echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | tee -a ~/.bashrc