v1.23.5
swapoff -a
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
apt update apt 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 update && apt install containerd.io systemctl status containerd
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 update apt install -y kubeadm kubelet kubectl kubernetes-cni
apt policy kubelet apt install -y kubelet=1.17.11-00 kubeadm=1.17.11-00 kubectl=1.17.11-00
kubeadm init
名前や、CIDRを指定する場合
kubeadm init --node-name master --pod-network-cidr=10.224.0.0/16
こんなのが表示されれば成功です。
Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: kubeadm join 172.16.0.82:6443 --token qc0yz3.rs9q3122p8s2mko1 \ --discovery-token-ca-cert-hash sha256:6687ea8b6dc4871f30edc0544b836e6ada87cf540bb4fb126b25b6f90177db88
export KUBECONFIG=/etc/kubernetes/admin.conf # kubectl get node NAME STATUS ROLES AGE VERSION master NotReady control-plane,master 83s v1.23.5
kubectl completion bash >/etc/bash_completion.d/kubectl
下記の方法でaliasによりもっと短いコマンドにできます。
2022.05.28 kubectl をaliasで短く
workerノードでも手順1~3を実行
その後下記でjoinする
kubeadm join 172.16.0.82:6443 --token qc0yz3.rs9q3122p8s2mko1 \ --discovery-token-ca-cert-hash sha256:6687ea8b6dc4871f30edc0544b836e6ada87cf540bb4fb126b25b6f90177db88
kubeadm token create --print-join-command
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# kubectl get node NAME STATUS ROLES AGE VERSION master NotReady control-plane,master 8m3s v1.23.5 worker01 NotReady <none> 3m8s v1.23.5 ↓ # kubectl get node NAME STATUS ROLES AGE VERSION master Ready control-plane,master 13m v1.23.5 worker01 Ready <none> 8m30s v1.23.5
kubernetes作成したばかりでは、Podネットワークは外部との通信できません。
Podから外部へ通信するには、IPマスカレードの設定を入れてあげる必要があります。