====== 12 Kubernetes ====== ===== 環境 ===== v1.23.5 ===== 1.Kubernetesの要件としてSwapの停止 ===== swapoff -a ===== 2.Containerd用意 ===== ==== Kernel モジュール ==== cat < ==== Kernel パラメータ ==== cat < ==== パッケージインストール ==== apt update apt install -y apt-transport-https ca-certificates curl software-properties-common ==== Docker GDG ==== curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - ==== Docker repo ==== add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" ==== install ==== apt update && apt install containerd.io systemctl status containerd ==== Containerdの設定 ==== mkdir -p /etc/containerd containerd config default | tee /etc/containerd/config.toml systemctl restart containerd ===== 3. kubernetesインストール ===== ==== GPG key ==== curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add ==== repogitory ==== apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" ==== install ==== 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 ===== 4. Kubernetsマスターノードセットアップ ===== 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 === kubectlを使えるように === export KUBECONFIG=/etc/kubernetes/admin.conf # kubectl get node NAME STATUS ROLES AGE VERSION master NotReady control-plane,master 83s v1.23.5 ==== kubectl 自動補完 ==== kubectl completion bash >/etc/bash_completion.d/kubectl 下記の方法でaliasによりもっと短いコマンドにできます。 [[50_dialy:2022:05:28]] ===== 5. workerノード ===== workerノードでも手順1~3を実行 その後下記でjoinする kubeadm join 172.16.0.82:6443 --token qc0yz3.rs9q3122p8s2mko1 \ --discovery-token-ca-cert-hash sha256:6687ea8b6dc4871f30edc0544b836e6ada87cf540bb4fb126b25b6f90177db88 ==== Worker Join token再作成 ==== kubeadm token create --print-join-command ===== 6.flannelインストール ===== 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 3m8s v1.23.5 ↓ # kubectl get node NAME STATUS ROLES AGE VERSION master Ready control-plane,master 13m v1.23.5 worker01 Ready 8m30s v1.23.5 ===== 7.Podから外部へ通信 ===== kubernetes作成したばかりでは、Podネットワークは外部との通信できません。 Podから外部へ通信するには、[[06_virtualization:05_container:17_kubernetes_ipmasquerade |IPマスカレード]]の設定を入れてあげる必要があります。 {{tag>Container Kubernetes}}