kubeadmでkubernetesをインストールする(ubuntu20.04, containerd + calico)
インストールメモが必要そうだったので、一応記載
v1.23.4で確認済み
とりあえずrootユーザーで実行前提
構成はマスターノード1台、ワーカーノードN台構成
# cat /etc/os-release NAME="Ubuntu" VERSION="20.04.4 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.4 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal
マスターノード、ワーカーノード共に実行
適当にアップデート
apt update -y && apt upgrade -y
スワップの廃止
swapoff -a
vi /etc/fstab + # /swap.img
ネットワーク関係
cat <<EOF | tee /etc/modules-load.d/containerd.conf overlay br_netfilter EOF modprobe overlay modprobe br_netfilter cat <<EOF | tee /etc/sysctl.d/99-kubernetes-cri.conf net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 EOF
システム反映
sysctl --system
containerd関連のインストール
apt-get install -y apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" apt-get update apt-get install containerd.io -y mkdir -p /etc/containerd containerd config default | tee /etc/containerd/config.toml systemctl restart containerd curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" apt-get update -y apt install kubeadm kubelet kubectl kubernetes-cni -y
再起動
reboot
マスターノードのみ、実行
pod-network-cidrは物理ネットワーク環境とかぶらないように。
kubeadm init --cri-socket=/run/containerd/containerd.sock --pod-network-cidr=10.245.0.0/16
最後に出てくる「kubeadm join ~ --discovery-token-ca-cert-hash sha256:xxxxxxxxxxxxxxxxx」までは別途保存しておく
kubeconfigの取得
ルートユーザーのみ。
export KUBECONFIG=/etc/kubernetes/admin.conf source ~/.bashrc
calicoのインストール
kubeadmから勝手にpod-network-cidrの情報を持ってきてくれるのね。
kubectl apply -f https://projectcalico.docs.tigera.io/manifests/calico.yaml
Nodeの情報を確認
ちょっと落ち着いて待とう
# kubectl get node NAME STATUS ROLES AGE VERSION master-0 Ready control-plane,master 5m v1.23.4
ワーカーノードのみ、実行
マスターノードででたあれ
kubeadm join ~ --discovery-token-ca-cert-hash sha256:xxxxxxxxxxxxxxxxx
確認
1分くらい待てばReadyになったかな。
# kubectl get node NAME STATUS ROLES AGE VERSION master-0 Ready control-plane,master 108m v1.23.4 worker-1 Ready <none> 97m v1.23.4 worker-2 Ready <none> 97m v1.23.4