LoginSignup
2
1

More than 1 year has passed since last update.

CentOS Stream 9でCRI-Oを使ってKubernetesクラスターをつくる1 マスターノード

Last updated at Posted at 2022-05-24

サマリー

・サポート切れのCentOS8は使わない
・非推奨のDockerは使わない(って書いてるけど下のリンクは読んだほうがいい)

Docker非推奨に対する誤解
https://jaco.udcp.info/entry/2020/12/03/172843

・できるだけ新しい1.24にしてみる
・今回はmasterとworkerをわけてちゃんとしたクラスターを組む

OSインストールと設定

CentOS Stream 9
Serverだけでインストール

rootのsshを許可

vim /etc/ssh/sshd_config
PermitRootLogin yes

Firewall止める

systemctl disable firewalld.service
systemctl stop firewalld
sysctl -p

SE Linux無効化

setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

Swap無効化

swapoff -a
vi /etc/fstab
/dev/mapper/cl-swap swap swap defaults 0 0 #コメントアウト

自分を含めを名前解決できるようにする

vi /etc/hosts
192.168.1.1 master #自分自身を名前解決できるようにする
192.168.1.2 worker2
192.168.1.3 worker3
192.168.1.4 worker4

CRI-Oインストール

export OS=CentOS_8_Stream
export VERSION=1.24:1.24.0 #2022/5現在最新

curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/devel:kubic:libcontainers:stable.repo
curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo

yum install cri-o

systemctl daemon-reload
systemctl start crio

kubeadmインストール

modprobe br_netfilter
lsmod | grep br_netfilter
sh -c 'echo "br_netfilter" > /etc/modules-load.d/br_netfilter.conf'

cat < /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet

echo "KUBELET_EXTRA_ARGS=--cgroup-driver=systemd" >> /etc/sysconfig/kubelet

systemctl daemon-reload
systemctl restart kubelet

kubeadmを使用したクラスターの作成

kubeadm config images pull
kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=10.(略)

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

#いらない
#export KUBECONFIG=/etc/kubernetes/admin.conf

1ノードクラスターにするときの大事なおまじない(書いたけど今回はやらない)

kubectl taint nodes --all node-role.kubernetes.io/master-

ダッシュボード

https://github.com/kubernetes/dashboard/releases
1.24と互換性がない。

とりあえず入れてみる。
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml

kubectl get pod -n kubernetes-dashboard

今回はここまで。次回はワーカーノード

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1