【初心者向け】Kubernetes学習向けのハンズオン(Linux(CentOS))

1. はじめに

kubernetes学習向けに、Linux(CentoS8)上にkubernetesを構築するハンズオンを記載してみました。初めてKubernetesを触る際にはハマるポイントがいくつかあるかと思いますので、ぜひ参考にしていただけると嬉しいです。

2. 前提環境

Windowsの物理サーバ上にVirtualBoxをインストールして、仮想ホストを構築しています。

<物理サーバ>
OS:Windows 11
VirtualBox:Version 7.0.22 r165102

<仮想サーバ>
OS:Centos8.5
*下記の記事に従ってネットワーク設定のみ変更済みです。
【VirtualBox】ゲストOS(CentOS)のネットワーク設定 ~SSH接続/インターネット接続~

仮想サーバについてはマスターノード1台を先に構築していき、途中でクローニングしてワーカーノード2台をつくる手順としています。

3. Kubernetesインストール方法

Step3-1:パッケージ更新
まずはマスターノードの構築を進めていきましょう。
パッケージを最新版に更新します。CentOS8はサポートが切れておりリポジトリのミラーサイトが停止しています。ルートユーザにスイッチして下記コマンドを実行し、リポジトリの設定をmirrorlistからbaseurlへ変更してからdnf upgradeコマンドを実行します。

[root@localhost ~]# sed -i 's/mirrorlist=/#mirrorlist=/g' /etc/yum.repos.d/CentOS-*
[root@localhost ~]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
[root@localhost ~]# dnf -y upgrade
Last metadata expiration check: 0:04:15 ago on Thu 26 Dec 2024 11:29:13 PM EST.
Dependencies resolved.
=============================================================================================
 Package                   Arch   Version                                    Repo       Size
=============================================================================================
Installing:
 kernel                    x86_64 4.18.0-348.7.1.el8_5                       baseos    7.0 M
Upgrading:
 accountsservice           x86_64 0.6.55-2.el8_5.2                           appstream 139 k
 accountsservice-libs      x86_64 0.6.55-2.el8_5.2                           appstream  96 k

~~omission~~

  systemd-container-239-51.el8_5.2.x86_64
  systemd-libs-239-51.el8_5.2.x86_64
  systemd-pam-239-51.el8_5.2.x86_64
  systemd-udev-239-51.el8_5.2.x86_64
Installed:
  kernel-4.18.0-348.7.1.el8_5.x86_64             kernel-core-4.18.0-348.7.1.el8_5.x86_64
  kernel-modules-4.18.0-348.7.1.el8_5.x86_64

Complete!

Step3-2:Dockerのインストール
Dockerをインストールするために、まずはデフォルトでインストールされているpodmanパッケージを削除します。podmanとはRedHat社主導で開発されているコンテナを管理するためのオープンソースですが、postmanがインストールされている状態だとDockerのインストールに失敗するので削除します。

[root@localhost ~]# dnf remove podman -y
Dependencies resolved.
=============================================================================================
 Package             Arch      Version                                   Repository     Size
=============================================================================================
Removing:
 podman              x86_64    3.3.1-9.module_el8.5.0+988+b1f0b741       @AppStream     48 M
Removing dependent packages:
 cockpit-podman      noarch    33-1.module_el8.5.0+890+6b136101          @AppStream    438 k
Removing unused dependencies:
 conmon              x86_64    2:2.0.29-1.module_el8.5.0+890+6b136101    @AppStream    164 k
 podman-catatonit    x86_64    3.3.1-9.module_el8.5.0+988+b1f0b741       @AppStream    760 k

Transaction Summary
=============================================================================================
Remove  4 Packages

Freed space: 49 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                     1/1
  Running scriptlet: cockpit-podman-33-1.module_el8.5.0+890+6b136101.noarch              1/1
  Erasing          : cockpit-podman-33-1.module_el8.5.0+890+6b136101.noarch              1/4
  Erasing          : podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                   2/4
  Running scriptlet: podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                   2/4
  Erasing          : podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64         3/4
  Erasing          : conmon-2:2.0.29-1.module_el8.5.0+890+6b136101.x86_64                4/4
  Running scriptlet: conmon-2:2.0.29-1.module_el8.5.0+890+6b136101.x86_64                4/4
  Verifying        : cockpit-podman-33-1.module_el8.5.0+890+6b136101.noarch              1/4
  Verifying        : conmon-2:2.0.29-1.module_el8.5.0+890+6b136101.x86_64                2/4
  Verifying        : podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64                   3/4
  Verifying        : podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64         4/4

Removed:
  cockpit-podman-33-1.module_el8.5.0+890+6b136101.noarch
  conmon-2:2.0.29-1.module_el8.5.0+890+6b136101.x86_64
  podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64
  podman-catatonit-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64

Complete!

続いてDockerインストールするために、containers-common(Podmanなどの設定ファイル、ドキュメントが含まれている)およびrunc(コンテの起動や動作を管理するCLIツール)も削除します。

[root@localhost ~]# dnf -y remove containers-common runc
Dependencies resolved.
=============================================================================================
 Package             Arch     Version                                     Repository    Size
=============================================================================================
Removing:
 containers-common   noarch   2:1-2.module_el8.5.0+890+6b136101           @AppStream   236 k
 runc                x86_64   1.0.2-1.module_el8.5.0+911+f19012f9         @AppStream    11 M
Removing dependent packages:
 buildah             x86_64   1.22.3-2.module_el8.5.0+911+f19012f9        @AppStream    28 M
Removing unused dependencies:
 container-selinux   noarch   2:2.167.0-1.module_el8.5.0+911+f19012f9     @AppStream    48 k
 criu                x86_64   3.15-3.module_el8.5.0+890+6b136101          @AppStream   1.4 M

~~omission~~

  Verifying        : fuse3-3.2.1-12.el8.x86_64                                          6/11
  Verifying        : fuse3-libs-3.2.1-12.el8.x86_64                                     7/11
  Verifying        : libnet-1.1.6-15.el8.x86_64                                         8/11
  Verifying        : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64                9/11
  Verifying        : runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64                   10/11
  Verifying        : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64            11/11

Removed:
  buildah-1.22.3-2.module_el8.5.0+911+f19012f9.x86_64
  container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch
  containers-common-2:1-2.module_el8.5.0+890+6b136101.noarch
  criu-3.15-3.module_el8.5.0+890+6b136101.x86_64
  fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64
  fuse3-3.2.1-12.el8.x86_64
  fuse3-libs-3.2.1-12.el8.x86_64
  libnet-1.1.6-15.el8.x86_64
  libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64
  runc-1.0.2-1.module_el8.5.0+911+f19012f9.x86_64
  slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64

Complete!

続いて、dockerインストールのためのリポジトリを追加します。

[root@localhost ~]# dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost ~]#

いよいよDockerのインストールです。下記コマンドを実行してください。

[root@localhost ~]# dnf -y install docker-ce docker-ce-cli containerd.io
Docker CE Stable - x86_64                                    385 kB/s |  66 kB     00:00
Dependencies resolved.
=============================================================================================
 Package               Arch   Version                                 Repository        Size
=============================================================================================
Installing:
 containerd.io         x86_64 1.6.32-3.1.el8                          docker-ce-stable  35 M
 docker-ce             x86_64 3:26.1.3-1.el8                          docker-ce-stable  27 M
 docker-ce-cli         x86_64 1:26.1.3-1.el8                          docker-ce-stable 7.8 M
Installing dependencies:
 container-selinux     noarch 2:2.167.0-1.module_el8.5.0+911+f19012f9 appstream         54 k
 fuse-overlayfs        x86_64 1.7.1-1.module_el8.5.0+890+6b136101     appstream         73 k
 fuse3                 x86_64 3.2.1-12.el8                            baseos            50 k
 fuse3-libs            x86_64 3.2.1-12.el8                            baseos            94 k
 libcgroup             x86_64 0.41-19.el8                             baseos            70 k
 libslirp              x86_64 4.4.0-1.module_el8.5.0+890+6b136101     appstream         70 k
 slirp4netns           x86_64 1.1.8-1.module_el8.5.0+890+6b136101     appstream         51 k
Installing weak dependencies:
 docker-buildx-plugin  x86_64 0.14.0-1.el8                            docker-ce-stable  14 M
 docker-ce-rootless-extras
                       x86_64 26.1.3-1.el8                            docker-ce-stable 5.0 M
 docker-compose-plugin x86_64 2.27.0-1.el8                            docker-ce-stable  13 M

Transaction Summary
=============================================================================================
Install  13 Packages

Total download size: 103 M
Installed size: 390 M
Downloading Packages:
(1/13): libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64. 218 kB/s |  70 kB     00:00
(2/13): fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x 211 kB/s |  73 kB     00:00
(3/13): slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_ 1.4 MB/s |  51 kB     00:00
(4/13): fuse3-3.2.1-12.el8.x86_64.rpm                        1.4 MB/s |  50 kB     00:00

~~Omission~~

  Verifying        : docker-ce-3:26.1.3-1.el8.x86_64                                   10/13
  Verifying        : docker-ce-cli-1:26.1.3-1.el8.x86_64                               11/13
  Verifying        : docker-ce-rootless-extras-26.1.3-1.el8.x86_64                     12/13
  Verifying        : docker-compose-plugin-2.27.0-1.el8.x86_64                         13/13

Installed:
  container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch
  containerd.io-1.6.32-3.1.el8.x86_64
  docker-buildx-plugin-0.14.0-1.el8.x86_64
  docker-ce-3:26.1.3-1.el8.x86_64
  docker-ce-cli-1:26.1.3-1.el8.x86_64
  docker-ce-rootless-extras-26.1.3-1.el8.x86_64
  docker-compose-plugin-2.27.0-1.el8.x86_64
  fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64
  fuse3-3.2.1-12.el8.x86_64
  fuse3-libs-3.2.1-12.el8.x86_64
  libcgroup-0.41-19.el8.x86_64
  libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64
  slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64

Complete!

Dockerのバージョンを確認してみましょう。Docker 26.1.3がンストールされていることが確認できました。

[root@localhost ~]# docker -v
Docker version 26.1.3, build b72abbb
[root@localhost ~]#

Step3-3:Dockerの起動および自動起動設定
dockerを起動してみましょう。status確認結果がActive: active (running)になっていれば成功です。

[root@localhost ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@localhost ~]#
[root@localhost ~]# systemctl start docker
[root@localhost ~]#
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2024-12-27 00:12:16 EST; 4s ago
     Docs: https://docs.docker.com
 Main PID: 61193 (dockerd)
    Tasks: 8
   Memory: 128.6M
   CGroup: /system.slice/docker.service
           mq61193 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

12月 27 00:12:12 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
12月 27 00:12:12 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:12.661560782-05:00" level=info msg="Starting up"
12月 27 00:12:12 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:12.843621634-05:00" level=info msg="Loading containers: start."
12月 27 00:12:15 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:15.974399679-05:00" level=info msg="Firewalld: interface docker0 alre>
12月 27 00:12:16 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:16.324439979-05:00" level=info msg="Loading containers: done."
12月 27 00:12:16 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:16.393309540-05:00" level=info msg="Docker daemon" commit=8e96db1 con>
12月 27 00:12:16 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:16.393541616-05:00" level=info msg="Daemon has completed initializati>
12月 27 00:12:16 localhost.localdomain dockerd[61193]: time="2024-12-27T00:12:16.533161451-05:00" level=info msg="API listen on /run/docker.sock"
12月 27 00:12:16 localhost.localdomain systemd[1]: Started Docker Application Container Engine.

Step3-4:その他設定
hostnamectlコマンドでホスト名を設定します。設定した後にexitしてから再度ルートユーザにスイッチすると、ホスト名が設定した名前に代わっていることが確認できます。

[root@localhost ~]# hostnamectl set-hostname masternode
[root@localhost ~]# exit
logout
[eeengineer@localhost ~]$ sudo su -
[sudo] password for eeengineer:
[root@masternode eeengineer]#

/etc/hostsファイルにレコードを追加することで、名前解決ができるように設定します。
あとで作成するworkernode2台分のレコードも追加しておきます。

[root@localhost ~]# vi /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.101 masternode   ##左記を追加##
192.168.56.102 workernode1  ##左記を追加##
192.168.56.103 workernode2  ##左記を追加##

SELinuxが有効だとkubernetesの各種リソースアクセスに失敗することがあるため、SELinuxの設定を無効化します。/etc/selinux/configのSELINUXの項目をdisabledにして再起動します。

[root@masternode ~]# vi /etc/selinux/config
[root@masternode ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled  ##左記の値をdisabledに修正##
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted  

[root@masternode ~]#shutdown -r now

再起動後にSELinuxが無効になっていることを確認します。getenforceコマンドの結果がDisabledになっていればOKです。

[root@masternode ~]# getenforce
Disabled
[root@masternode ~]#

続いてswapの設定を無効にします。swapを有効にしているとpodが想定外にメモリを使用して性能影響出る可能性があるので、無効にしておく必要があります。下記の通り、Swapの行の使用量が0Bとなっていることを確認下さい。

[root@masternode ~]# swapoff -a
[root@masternode ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.8Gi       519Mi       442Mi        10Mi       854Mi       1.1Gi
Swap:            0B          0B          0B
[root@masternode ~]# 

再起動するとswapが最有効化されてしまうので、fstabの設定も変更しておきましょう。下記の通りswapに関する設定をコメントアウトしています。
#/dev/mapper/cl-swap none swap defaults 0 0

[root@masternode ~]# vi /etc/fstab
[root@masternode ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Dec 27 00:57:47 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=4b72b430-2959-449c-a411-60d253f20ad9 /boot                   xfs     defaults        0 0
#/dev/mapper/cl-swap     none                    swap    defaults        0 0  ##左記の設定をコメントアウト##
[root@masternode ~]# 

kubernetesの動作に必要な通信を制限しないように、firewallを停止します。

[root@masternode ~]# systemctl stop firewalld
[root@masternode ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@masternode ~]#
[root@masternode ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabl>
   Active: inactive (dead) since Fri 2024-12-27 16:58:46 EST; 44s ago
     Docs: man:firewalld(1)
 Main PID: 894 (code=exited, status=0/SUCCESS)

12月 27 16:24:41 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:24:41 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:24:42 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:24:42 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:24:42 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:24:42 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:24:42 masternode firewalld[894]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w1>
12月 27 16:58:45 masternode systemd[1]: Stopping firewalld - dynamic firewall daemon...
12月 27 16:58:46 masternode systemd[1]: firewalld.service: Succeeded.
12月 27 16:58:46 masternode systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@masternode ~]#

Step3-5:Kubernetesのインストール
Kubernetesのリポジトリを設定します。インストールしたいバージョンを指定して下さい。例としてv1.29をインストールするリポジトリとしています。

[root@masternode ~]# vi /etc/yum.repos.d/kubernetes.repo
[root@masternode ~]# cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni

[root@masternode ~]#

kubelet、kubeadm、kubectlをインストールします。
kubelet:kubernetesクラスタ内の各ノードで動作するエージェント
kubeadm:kubernetesクラスタの初期化やワーカノードのクラスタ追加など、kubernetesを構築するうえで必要なコンポーネント
kubectl:マスターノードと通信するためのコマンドラインツール

[root@masternode ~]# dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Kubernetes                                                    53 kB/s |  31 kB     00:00
Dependencies resolved.
=============================================================================================
 Package                      Architecture Version                    Repository        Size
=============================================================================================
Installing:
 kubeadm                      x86_64       1.29.12-150500.1.1         kubernetes       9.8 M
 kubectl                      x86_64       1.29.12-150500.1.1         kubernetes        10 M
 kubelet                      x86_64       1.29.12-150500.1.1         kubernetes        19 M
Installing dependencies:
 conntrack-tools              x86_64       1.4.4-10.el8               baseos           204 k
 cri-tools                    x86_64       1.29.0-150500.1.1          kubernetes       8.2 M
 kubernetes-cni               x86_64       1.3.0-150500.1.1           kubernetes       6.7 M
 libnetfilter_cthelper        x86_64       1.0.0-15.el8               baseos            24 k
 libnetfilter_cttimeout       x86_64       1.0.0-11.el8               baseos            24 k
 libnetfilter_queue           x86_64       1.0.4-3.el8                baseos            31 k

Transaction Summary
=============================================================================================
Install  9 Packages

Total download size: 54 M
Installed size: 298 M
Downloading Packages:
(1/9): libnetfilter_cttimeout-1.0.0-11.el8.x86_64.rpm         86 kB/s |  24 kB     00:00
(2/9): conntrack-tools-1.4.4-10.el8.x86_64.rpm               695 kB/s | 204 kB     00:00
(3/9): libnetfilter_queue-1.0.4-3.el8.x86_64.rpm             867 kB/s |  31 kB     00:00
(4/9): libnetfilter_cthelper-1.0.0-15.el8.x86_64.rpm          42 kB/s |  24 kB     00:00
(5/9): kubeadm-1.29.12-150500.1.1.x86_64.rpm                  14 MB/s | 9.8 MB     00:00
(6/9): kubectl-1.29.12-150500.1.1.x86_64.rpm                  10 MB/s |  10 MB     00:00
(7/9): kubelet-1.29.12-150500.1.1.x86_64.rpm                  19 MB/s |  19 MB     00:00
(8/9): kubernetes-cni-1.3.0-150500.1.1.x86_64.rpm            5.9 MB/s | 6.7 MB     00:01
(9/9): cri-tools-1.29.0-150500.1.1.x86_64.rpm                710 kB/s | 8.2 MB     00:11
---------------------------------------------------------------------------------------------
Total                                                        4.5 MB/s |  54 MB     00:12
Kubernetes                                                   5.3 kB/s | 1.7 kB     00:00
Importing GPG key 0x9A296436:
 Userid     : "isv:kubernetes OBS Project <isv:kubernetes@build.opensuse.org>"
 Fingerprint: DE15 B144 86CD 377B 9E87 6E1A 2346 54DA 9A29 6436
 From       : https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                     1/1
  Installing       : kubernetes-cni-1.3.0-150500.1.1.x86_64                              1/9

~~Omission~~

  Verifying        : kubelet-1.29.12-150500.1.1.x86_64                                   8/9
  Verifying        : kubernetes-cni-1.3.0-150500.1.1.x86_64                              9/9

Installed:
  conntrack-tools-1.4.4-10.el8.x86_64          cri-tools-1.29.0-150500.1.1.x86_64
  kubeadm-1.29.12-150500.1.1.x86_64            kubectl-1.29.12-150500.1.1.x86_64
  kubelet-1.29.12-150500.1.1.x86_64            kubernetes-cni-1.3.0-150500.1.1.x86_64
  libnetfilter_cthelper-1.0.0-15.el8.x86_64    libnetfilter_cttimeout-1.0.0-11.el8.x86_64
  libnetfilter_queue-1.0.4-3.el8.x86_64

Complete!
[root@masternode ~]#

Step3-6:各種起動設定
まずkubeletを起動します。

[root@masternode ~]# systemctl enable kubelet
Created symlink /etc/systemd/system/multi-user.target.wants/kubelet.service → /usr/lib/systemd/system/kubelet.service.
[root@masternode ~]# systemctl start kubelet
[root@masternode ~]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since Fri 2025-01-03 15:39:36 EST; 1h 5min ago
     Docs: https://kubernetes.io/docs/
 Main PID: 963 (kubelet)
    Tasks: 13 (limit: 11272)
   Memory: 79.2M
   CGroup: /system.slice/kubelet.service
           └─963 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container->

続いてcontainerdサービスのconfigファイルを削除してから、containerdサービスを再起動します。この操作を実施しないと次のkubernetesの初期化コマンドが失敗します。

[root@masternode ~]# rm -f /etc/containerd/config.toml
[root@masternode ~]# systemctl restart containerd
[root@masternode ~]# systemctl status containerd
● containerd.service - containerd container runtime
   Loaded: loaded (/usr/lib/systemd/system/containerd.service; disabled; vendor preset: disa>
   Active: active (running) since Sat 2024-12-28 18:34:06 EST; 5s ago
     Docs: https://containerd.io
  Process: 3099 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
 Main PID: 3101 (containerd)
    Tasks: 9
   Memory: 18.0M
   CGroup: /system.slice/containerd.service
           └─3101 /usr/bin/containerd

Dec 28 18:34:06 masternode containerd[3101]: time="2024-12-28T18:34:06.370185908-05:00" leve>
~~Omission~~
Dec 28 18:34:06 masternode containerd[3101]: time="2024-12-28T18:34:06.388392959-05:00" leve>
Dec 28 18:34:06 masternode systemd[1]: Started containerd container runtime.
[root@masternode ~]#

4. Kubernetes設定

Step4-1:Kubernetes初期化(マスターノード)
続いてkubernetesを初期化していきます。下記の通り環境に合わせてIPアドレスを設定します。
–apiserver-advertise-address:マスターノードのIPアドレス
–pod-network-cidr:podが所属するネットワークのIPアドレス帯

[root@masternode ~]# kubeadm init --service-cidr 10.96.0.0/12 --pod-network-cidr 192.168.100.0/24 --apiserver-advertise-address 192.168.56.101
I0102 17:43:57.246212    3390 version.go:256] remote version is much newer: v1.32.0; falling back to: stable-1.29
[init] Using Kubernetes version: v1.29.12
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster

~~Omission~~

[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

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 192.168.56.101:6443 --token 4wlx5x.0ga9j0l3roed4xco \
        --discovery-token-ca-cert-hash sha256:5240668f062fe73cbb97d13e103590f5777ffbd215482037d8b91590155d817c
[root@masternode ~]#

結果として出力された下記コマンドは、ワーカノードをクラスタに参加させる際に実行するコマンドとなりますのでどこかにメモしておきましょう。


下記ログをどこかに保存しておいて下さい。

kubeadm join 192.168.56.101:6443 –token 4wlx5x.0ga9j0l3roed4xco \
–discovery-token-ca-cert-hash sha256:5240668f062fe73cbb97d13e103590f5777ffbd215482037d8b91590155d817c

続いて、コマンド結果のインストラクションの通り、configファイルをコピーします。

[root@masternode ~]# mkdir -p $HOME/.kube
[root@masternode ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@masternode ~]# chown $(id -u):$(id -g) $HOME/.kube/config
[root@masternode ~]# ll  $HOME/.kube/config
-rw------- 1 root root 5654 Dec 28 18:46 /root/.kube/config
[root@masternode ~]# export KUBECONFIG=/etc/kubernetes/admin.conf

マスターノード上で下記コマンドを実行して下さい。workernodeが表示されていれば成功です。この時点ではネットワーク設定がまだなのでSTATUSはNotReadyになっております。

[root@masternode ~]# kubectl get nodes
NAME          STATUS     ROLES           AGE     VERSION
masternode    NotReady   control-plane   36m     v1.29.12
[root@masternode ~]#

5. CNI(Container Network interface)設定

続いて、Pod間通信を実現するためのContainer Network Interface (CNI)を設定していきます。CNIにはいくつか種類がありますが、今回は一般的に用いられているCalicoをインストールしていきます。

Step5-1:Calico管理ツールの導入

まず、tigers-operatorというCalicoを導入・管理を行うツールを導入していきます。

[root@masternode ~]# kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/tigera-operator.yaml
namespace/tigera-operator created
customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/bgpfilters.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created

~~Omission~~

customresourcedefinition.apiextensions.k8s.io/imagesets.operator.tigera.io created
customresourcedefinition.apiextensions.k8s.io/installations.operator.tigera.io created
customresourcedefinition.apiextensions.k8s.io/tigerastatuses.operator.tigera.io created
serviceaccount/tigera-operator created
clusterrole.rbac.authorization.k8s.io/tigera-operator created
clusterrolebinding.rbac.authorization.k8s.io/tigera-operator created
deployment.apps/tigera-operator created
[root@masternode ~]#

tigera-operatorが正常に起動していることを確認しましょう。下記のようなコマンド結果が返ってくれば成功です。

[root@masternode ~]# kubectl get ns
NAME              STATUS   AGE
default           Active   30m
kube-node-lease   Active   30m
kube-public       Active   30m
kube-system       Active   30m
tigera-operator   Active   15s
[root@masternode ~]#
[root@masternode ~]# kubectl -n tigera-operator get deployment
NAME              READY   UP-TO-DATE   AVAILABLE   AGE
tigera-operator   1/1     1            1           69s
[root@masternode ~]# kubectl -n tigera-operator get pod
NAME                               READY   STATUS    RESTARTS   AGE
tigera-operator-76c4974c85-xb58g   1/1     Running   0          78s
[root@masternode ~

Step5-2:Calicoの導入

続いてCalicoをデプロイしていきます。githubからcustom-resources.yamlファイルをダウンロードします。

[root@masternode ~]# wget https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/custom-resources.yaml
--2025-01-01 17:03:44--  https://raw.githubusercontent.com/projectcalico/calico/v3.29.1/manifests/custom-resources.yaml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 777 [text/plain]
Saving to: ‘custom-resources.yaml’

custom-resources.yaml                           100%[====================================================================================================>]     777  --.-KB/s    in 0.04s

2025-01-01 17:03:44 (18.6 KB/s) - ‘custom-resources.yaml’ saved [777/777]
[root@masternode ~]#

custom-resources.yamlにPod間通信で使うIPアドレスの設定があるので、デフォルトのIPアドレスから環境に合わせたIPアドレスに変更します。下記の通り、cidrの項目のみ変更しています。

[root@masternode ~]# vi custom-resources.yaml
[root@masternode ~]# cat custom-resources.yaml
# This section includes base Calico installation configuration.
# For more information, see: https://docs.tigera.io/calico/latest/reference/installation/api#operator.tigera.io/v1.Installation
apiVersion: operator.tigera.io/v1
kind: Installation
metadata:
  name: default
spec:
  # Configures Calico networking.
  calicoNetwork:
    ipPools:
    - name: default-ipv4-ippool
      blockSize: 26
      cidr: 10.0.2.0/24  ##この項目を環境に合わせて変更
      encapsulation: VXLANCrossSubnet
      natOutgoing: Enabled
      nodeSelector: all()

---

# This section configures the Calico API server.
# For more information, see: https://docs.tigera.io/calico/latest/reference/installation/api#operator.tigera.io/v1.APIServer
apiVersion: operator.tigera.io/v1
kind: APIServer
metadata:
  name: default
spec: {}

[root@masternode ~]#

IPアドレスを編集したcustom-resources.yamlを適用します。

[root@masternode ~]# kubectl create -f custom-resources.yaml
installation.operator.tigera.io/default created
apiserver.operator.tigera.io/default created

yaml適用後の状態だとマスターノードでpodを起動できないので、下記コマンドを実行してtaint設定を外し、マスターノードでもpodが起動できるようにして下さい。

[root@masternode ~]# kubectl taint nodes --all node-role.kubernetes.io/control-plane-
node/masternode untainted
[root@masternode ~]# kubectl describe node masternode | grep -i taint
Taints:             <none>

Calicoによるネットワーク設定が既存のNetworkManagerの設定と干渉しないように下記の設定を入れておいて下さい。

[root@masternode ~]# vi /etc/NetworkManager/conf.d/calico.conf
[root@masternode ~]# cat /etc/NetworkManager/conf.d/calico.conf
[keyfile]
unmanaged-devices=interface-name:cali*;interface-name:tunl*;interface-name:vxlan.calico
[root@masternode ~]#

マスターノードのnodesの状態を確認してきましょう。必要なコンポーネントが起動してくるのに時間がかかるので、下記ステータスになっていなかったらしばらく待ってみてください。

[root@masternode ~]# kubectl get nodes
NAME         STATUS   ROLES           AGE   VERSION
masternode   Ready    control-plane   49m   v1.29.12
[root@masternode ~]
[root@masternode ~]# kubectl get nodes -o wide
NAME         STATUS   ROLES           AGE   VERSION    INTERNAL-IP      EXTERNAL-IP   OS-IMAGE         KERNEL-VERSION                CONTAINER-RUNTIME
masternode   Ready    control-plane   26m   v1.29.12   192.168.56.101   <none>        CentOS Linux 8   4.18.0-348.7.1.el8_5.x86_64   containerd://1.6.32
[root@masternode ~]
[root@masternode ~]# kubectl get pods -n calico-system
NAME                                      READY   STATUS    RESTARTS        AGE
calico-kube-controllers-d6c6469d9-crc5m   1/1     Running   1 (35m ago)     42m
calico-node-zvcnb                         1/1     Running   3 (14m ago)     43m
calico-typha-698c9f99db-5vcbj             1/1     Running   2 (6m41s ago)   43m
csi-node-driver-w4644                     2/2     Running   0               45m
[root@masternode ~]#

6. ワーカーノードの構築

Step6-1:ワーカーノードのクローニング
マスターノードにてスナップショットを取得し、ワーカーノードをクローニングします。今回は2台のワーカーノードをクローニングで作成していきます。例としてワーカノード#1で実行した手順を記載しますので、#2についても同様に設定して下さい。

Step6-2:ワーカーノードのNW設定

IPアドレスが重複しないようにenp0s3、enp0s8の設定ファイルを修正してNetwork設定を反映します。下記にワーカーノード#1の設定例を記載します。

[root@workernode1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
#UUID=c62f40fe-33c6-46c0-a32c-2f0b7142d923
DEVICE=enp0s3
ONBOOT=yes
IPADDR=10.0.2.102 ##左記の値を変更##
NETMASK=255.255.255.0
GATEWAY=10.0.2.1

[root@workernode1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s8
#UUID=c62f40fe-33c6-46c0-a32c-2f0b7142d923
DEVICE=enp0s8
ONBOOT=yes
IPADDR=192.168.56.102 ##左記の値を変更##
NETMASK=255.255.255.0
[root@workernode1 ~]# systemctl restart NetworkManager
[root@workernode1 ~]# nmcli con down enp0s3 ; nmcli con up enp0s3
[root@workernode1 ~]# nmcli con down enp0s8 ; nmcli con up enp0s8
[root@workernode1 ~]#

Step6-3:ワーカーノードのクラスタ追加
続いて、ワーカノードをkubernetesクラスタに参加させます。ワーカノードをクローニングした際に作成されたconfファイルが配置されているとクラスタ追加時にエラーとなるため、下記の通りkubletを停止してからconfファイルを退避して下さい。

[root@workernode1 ~]# systemctl stop kubelet
[root@workernode1 ~]# mv /etc/kubernetes/kubelet.conf /tmp/
[root@workernode1 ~]# mv /etc/kubernetes/pki/ca.crt /tmp/
[root@workernode1 ~]# mv /etc/kubernetes/bootstrap-kubelet.conf /tmp/
[root@workernode1 ~]#

4-1で出力されたコマンドを実行します。「This node has joined the cluster:」というメッセージが出れば成功です。

[root@workernode1 ~]# kubeadm join 192.168.56.101:6443 --token m3dukz.0q28rbp1jzrg5i3r         --discovery-token-ca-cert-hash sha256:1726cdd380ae5372c8b39c7dc109cc6e62a06467b9aa40ce2d0ba4de4b09f839 --v=5
I0101 19:29:31.316713    5607 join.go:413] [preflight] found NodeName empty; using OS hostname as NodeName
I0101 19:29:31.318849    5607 initconfiguration.go:122] detected and using CRI socket: unix:///var/run/containerd/containerd.sock
[preflight] Running pre-flight checks
I0101 19:29:31.325048    5607 preflight.go:93] [preflight] Running general checks
I0101 19:29:31.327250    5607 checks.go:280] validating the existence of file /etc/kubernetes/kubelet.conf
I0101 19:29:31.330689    5607 checks.go:280] validating the existence of file /etc/kubernetes/bootstrap-kubelet.conf
I0101 19:29:31.330961    5607 checks.go:104] validating the container runtime

~~Omission~~

I0101 19:29:31.863503    5607 checks.go:329] validating the contents of file /proc/sys/net/ipv4/ip_forward
I0101 19:29:31.863580    5607 join.go:532] [preflight] Discovering cluster-info
I0101 19:29:31.864627    5607 token.go:80] [discovery] Created cluster-info discovery client, requesting info from "192.168.56.101:6443"
I0101 19:29:37.506881    5607 token.go:118] [discovery] Requesting info from "192.168.56.101:6443" again to validate TLS against the pinned public key
I0101 19:29:37.769258    5607 token.go:135] [discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.56.101:6443"
I0101 19:29:37.769547    5607 discovery.go:52] [discovery] Using provided TLSBootstrapToken as authentication credentials for the join process
I0101 19:29:37.769588    5607 join.go:546] [preflight] Fetching init configuration
I0101 19:29:37.769644    5607 join.go:592] [preflight] Retrieving KubeConfig objects
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
I0101 19:29:39.024628    5607 kubeproxy.go:55] attempting to download the KubeProxyConfiguration from ConfigMap "kube-proxy"

~~Omission~~

I0101 19:29:40.998126    5607 controlplaneprepare.go:225] [download-certs] Skipping certs download
I0101 19:29:40.998138    5607 kubelet.go:121] [kubelet-start] writing bootstrap kubelet config file at /etc/kubernetes/bootstrap-kubelet.conf
I0101 19:29:40.998780    5607 kubelet.go:136] [kubelet-start] writing CA certificate at /etc/kubernetes/pki/ca.crt
I0101 19:29:40.999585    5607 kubelet.go:157] [kubelet-start] Checking for an existing Node in the cluster with name "workernode1" and status "Ready"
I0101 19:29:41.286851    5607 kubelet.go:172] [kubelet-start] Stopping the kubelet
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
I0101 19:29:42.736915    5607 cert_rotation.go:137] Starting client certificate rotation controller
I0101 19:29:42.738817    5607 kubelet.go:220] [kubelet-start] preserving the crisocket information for the node
I0101 19:29:42.739151    5607 patchnode.go:31] [patchnode] Uploading the CRI Socket information "unix:///var/run/containerd/containerd.sock" to the Node API object "workernode1" as an annotation

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

Kubernetesのインストール、設定の手順は以上となります。最後にマスターノード上で下記コマンドを実行し、nodeのSTATUSがReadyになっていることを確認して下さい。Readyになるまでしばらく時間がかかるので、Readyになっていなかったら時間をおいてコマンドを再実行してみて下さい。

[root@masternode ~]# kubectl get nodes -o wide
NAME          STATUS   ROLES           AGE     VERSION    INTERNAL-IP      EXTERNAL-IP   OS-IMAGE         KERNEL-VERSION                CONTAINER-RUNTIME
masternode    Ready    control-plane   66m     v1.29.12   192.168.56.101   <none>        CentOS Linux 8   4.18.0-348.7.1.el8_5.x86_64   containerd://1.6.32
workernode1   Ready    <none>          44m     v1.29.12   192.168.56.102   <none>        CentOS Linux 8   4.18.0-348.7.1.el8_5.x86_64   containerd://1.6.32
workernode2   Ready    <none>          5m36s   v1.29.12   192.168.56.103   <none>        CentOS Linux 8   4.18.0-348.7.1.el8_5.x86_64   containerd://1.6.32
[root@masternode ~]#

7.kubernetes動作確認

続いてkubernetesの動作確認のために、nginxのサンプルイメージをデプロイしてみましょう。まずは下記の通りymlファイルを作成して下さい。

[root@masternode ~]# vi nginx-deploy-sample.yml
[root@masternode ~]# cat nginx-deploy-sample.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 80
    nodePort: 30080
    protocol: TCP
  selector:
    app: nginx
[root@masternode ~]#

作成したマニフェストを適用します。下記の通りpodのステータスがRunningになっていれば成功です。

[root@masternode ~]# kubectl apply -f nginx-deploy-sample.yml
deployment.apps/nginx-deployment created
service/nginx-service created
[root@masternode ~]# kubectl get po -l app=nginx
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-86dcfdf4c6-65wwz   1/1     Running   0          11m
nginx-deployment-86dcfdf4c6-mdgkl   1/1     Running   0          11m

下記のとおりpodのNAMEを指定してdescribeコマンドを実行することで、podの詳細情報を出力させることができます。

[root@masternode ~]# kubectl describe pod nginx-deployment-5b455f597c-2nwtr
Name:             nginx-deployment-5b455f597c-2nwtr
Namespace:        default
Priority:         0
Service Account:  default
Node:             workernode2/192.168.56.103
Start Time:       Fri, 03 Jan 2025 08:39:41 -0500
Labels:           app=nginx
                  pod-template-hash=5b455f597c
Annotations:      cni.projectcalico.org/containerID: 2527b4319d3a97cdd29ce87a609ba59adba8c42ec08a04a07a9bd0116e77a180
                  cni.projectcalico.org/podIP: 192.168.100.133/32
                  cni.projectcalico.org/podIPs: 192.168.100.133/32
Status:           Running
IP:               192.168.100.133. ##このIPアドレスに対してcurlコマンドを実行する
IPs:
  IP:           192.168.100.133
Controlled By:  ReplicaSet/nginx-deployment-5b455f597c
Containers:
  nginx:
    Container ID:   containerd://215ffdc5b64e490030e26bd094788737525a22dfcb7c094fa70753cf188b9402
    Image:          nginx:1.14.2
    Image ID:       docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 03 Jan 2025 15:41:19 -0500
    Last State:     Terminated
      Reason:       Unknown
      Exit Code:    255
      Started:      Fri, 03 Jan 2025 08:39:47 -0500
      Finished:     Fri, 03 Jan 2025 15:39:49 -0500
    Ready:          True
    Restart Count:  1
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-nhskw (ro)
Conditions:
  Type                        Status
  PodReadyToStartContainers   True
  Initialized                 True
  Ready                       True
  ContainersReady             True
  PodScheduled                True
Volumes:
  kube-api-access-nhskw:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason          Age                From               Message
  ----    ------          ----               ----               -------
  Normal  Scheduled       7h25m              default-scheduler  Successfully assigned default/nginx-deployment-5b455f597c-2nwtr to workernode2
  Normal  Pulled          7h25m              kubelet            Container image "nginx:1.14.2" already present on machine
  Normal  Created         7h25m              kubelet            Created container nginx
  Normal  Started         7h25m              kubelet            Started container nginx
  Normal  SandboxChanged  23m (x2 over 24m)  kubelet            Pod sandbox changed, it will be killed and re-created.
  Normal  Pulled          23m                kubelet            Container image "nginx:1.14.2" already present on machine
  Normal  Created         23m                kubelet            Created container nginx
  Normal  Started         23m                kubelet            Started container nginx

nginxのWelcomeページにアクセスしてみましょう。上記コマンドの結果にIPの項目がありますので、そのIPアドレスに対してcurlコマンドを実行してみて下さい。「Welcome to nginx!」というページが表示されていれば成功です。

[root@masternode ~]# curl 192.168.100.133
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@masternode ~]#

7. まとめ

以上がLinux (CentOS 8)上にkubernetesをインストールする方法になります。kuberentesを提供しているクラウドサービスがいくつもあるので、オンプレ環境にkubernetesをいちから構築する機会は多くはないかもしれないですが、kubernetesの理解を深めるためにもぜひ取り組んでもらえると良いかと思います。

8. 参考文献

コメント