環境
- Ubuntu 20.04
- Kubernetes v1.24
事前設定
cat > /etc/modules-load.d/containerd.conf <<EOF overlay br_netfilter EOF modprobe overlay modprobe br_netfilter cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 EOF sysctl --system
apt install -y iptables arptables ebtables update-alternatives --set iptables /usr/sbin/iptables-legacy update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy update-alternatives --set arptables /usr/sbin/arptables-legacy update-alternatives --set ebtables /usr/sbin/ebtables-legacy
swapを無効にしておく
swapoff -a
containerdのインストール
## 競合するパッケージを削除 apt remove docker-ce containerd docker-ce-cli docker-ce-rootless-extras ## Docker公式のGPG鍵を追加 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - ## Dockerのaptリポジトリの追加 add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" apt install -y containerd.io
containerdの設定
mkdir -p /etc/containerd containerd config default > /etc/containerd/config.toml systemctl restart containerd systemctl enable containerd
kubeadmコマンドのインストール
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF apt update && apt install -y kubelet kubeadm kubectl && apt-mark hold kubelet kubeadm kubectl # 確認 kubeadm version -o yaml
インストール
cluster-config.yaml を作成して以下
apiVersion: kubeadm.k8s.io/v1beta3 kind: InitConfiguration localAPIEndpoint: advertiseAddress: 192.168.16.14 --- apiVersion: kubeadm.k8s.io/v1beta3 kind: ClusterConfiguration clusterName: myhome networking: serviceSubnet: "10.96.0.0/16" podSubnet: "10.189.0.0/16"
kubeadm init --config cluster-config.yaml --upload-certs
2CPU以上じゃないとエラーになる。 1CPUでも動かしたいなら --ignore-preflight-errors=NumCPU
つける
export KUBECONFIG=/etc/kubernetes/admin.conf
ubuntu02に以下を実行
kubeadm join 192.168.16.11:6443 --token klfgvg.morpmm4xc3xfgrng \ --discovery-token-ca-cert-hash sha256:7ff0537b9d474b006e53c60e2f3a19239aa772f1543d39593b5bf1d6ef4fd2d9
後から追加したい場合
kubeadm token create --print-join-command
最初のノード以外はホスト側で以下実行
sudo mkdir -p /etc/kubernetes/manifests
Calico
kubectl create -f https://docs.projectcalico.org/archive/v3.21/manifests/tigera-operator.yaml
複数NICあるとREADYになってくれないのでネットワーク帯域を指定してあげる 詳細
kubectl set env daemonset/calico-node -n kube-system IP_AUTODETECTION_METHOD=cidr=192.168.16.0/24
Calicoのインストールまで完了すれば全ノードがReadyになるはず
❯ kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME ubuntu01 Ready control-plane 4m54s v1.24.3 192.168.16.11 <none> Ubuntu 20.04.4 LTS 5.15.0-41-generic containerd://1.5.11-gke.0 ubuntu02 Ready <none> 4m18s v1.24.3 192.168.16.12 <none> Ubuntu 20.04.4 LTS 5.15.0-41-generic containerd://1.5.11-gke.0
MetalLB
- MetalLB L2 モードをインストール
- 負荷分散の機能はない
- v0.13だとバグって上手くインストールできなかったので見送り
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
metallb-config.yaml作成して以下
--- apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | address-pools: - name: default protocol: layer2 addresses: - 192.168.16.30-192.168.16.60
$ kubectl create -n metallb-system -f metallb-config.yaml
istio
istioctl version client version: 1.14.1 control plane version: 1.14.1 data plane version: 1.14.1 (2 proxies)
istioctl install --set profile=demo -y --set meshConfig.outboundTrafficPolicy.mode=ALLOW_ANY --set meshConfig.accessLogFile=/dev/stdout --vklog=9
アドオンをインストールする適当なディレクトリにいってclone
git clone https://github.com/istio/istio.git cd istio git checkout 1.14.1
適用
kubectl apply -f ./samples/addons