0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kubernetesインストール centos9

Last updated at Posted at 2024-11-17

OS centos9 最小パッケージで実施

3台構成

kube1 kube2 kube3

参考URL
https://www.youtube.com/watch?v=UN2IibUnztk

インストール前準備

hostsに追加

[root@kube1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.190 kube1
192.168.2.191 kube2
192.168.2.192 kube3

swapのOFF

swapoff -a

firewalld無効

systemctl disable firewalld

SElinux無効

grubby --update-kernel ALL --args selinux=0

今回の構成

modprobe br_netfilter
cat /proc/sys/net/bridge/bridge-nf-call-iptables
1であること
dockerがインストールされている場合は削除する
yum install yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

コンテナ関連パッケージインストール

yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

コンテナランタイムファイル生成

containerd config default | tee /etc/containerd/config.toml

systemd cgroupドライバーを構成する

vi /etc/containerd/config.toml

SystemdCgroup = false
↓
SystemdCgroup = true

dockerを起動します

systemctl start docker
systemctl enable docker
docker run hello-world

kubernetes.repoを構成します

アップデートから「kubelet kubeadm kubectl cri-tools kubernetes-cni」を除外対象とする

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF

disableexcludesを利用すればexcludeの設定を無視してアップデートできる。

yum install kubelet kubeadm kubectl --disableexcludes=kubernetes

ネットワークは「Calico」を用います。

yum install wget
wget https://raw.githubusercontent.com/projectcalico/calico/master/manifests/calico.yaml
kubectl apply -f calico.yaml
kubectl get nodes


[root@kube1 ~]# kubectl get pods -A
NAMESPACE     NAME                                       READY   STATUS              RESTARTS   AGE
kube-system   calico-kube-controllers-5f9c988956-7qxp9   0/1     ContainerCreating   0          33s
kube-system   calico-node-8k4tg                          0/1     Running             0          33s
kube-system   coredns-5dd5756b68-mtb6q                   1/1     Running             0          56m
kube-system   coredns-5dd5756b68-xgx6m                   1/1     Running             0          56m
kube-system   etcd-kube1                                 1/1     Running             0          56m
kube-system   kube-apiserver-kube1                       1/1     Running             0          56m
kube-system   kube-controller-manager-kube1              1/1     Running             0          56m
kube-system   kube-proxy-lxcrx                           1/1     Running             0          56m
kube-system   kube-scheduler-kube1                       1/1     Running             0          56m
[root@kube1 ~]#
[root@kube1 ~]#
[root@kube1 ~]# kubectl get pods -A
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
kube-system   calico-kube-controllers-5f9c988956-7qxp9   1/1     Running   0          51s
kube-system   calico-node-8k4tg                          1/1     Running   0          51s
kube-system   coredns-5dd5756b68-mtb6q                   1/1     Running   0          56m
kube-system   coredns-5dd5756b68-xgx6m                   1/1     Running   0          56m
kube-system   etcd-kube1                                 1/1     Running   0          56m
kube-system   kube-apiserver-kube1                       1/1     Running   0          56m
kube-system   kube-controller-manager-kube1              1/1     Running   0          56m
kube-system   kube-proxy-lxcrx                           1/1     Running   0          56m
kube-system   kube-scheduler-kube1                       1/1     Running   0          56m
[root@kube1 ~]# kubectl get pods -A

各ノードで以下のコマンドを実行

kubeadm join 192.168.2.190:6443 --token uug8oj.nmuad2ruvkw25plr \
        --discovery-token-ca-cert-hash sha256:895b042063790369cebb6226739588033ed4badb02dea65199dd89367ecbb27e

追加されたことを確認する

root@kube1 ~]# kubectl get nodes
NAME    STATUS     ROLES           AGE   VERSION
kube1   Ready      control-plane   96m   v1.28.15
kube2   Ready      <none>          34s   v1.28.15
kube3   NotReady   <none>          22s   v1.28.15
[root@kube1 ~]#
[root@kube1 ~]#

また更新します!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?