LoginSignup
2
2
お題は不問!Qiita Engineer Festa 2024で記事投稿!
Qiita Engineer Festa20242024年7月17日まで開催中!

AlmaLinuxでシングルノードローカルkubernetes環境を作る

Last updated at Posted at 2024-06-10

0.はじめに

docker,kubernetesを知ってから、触ってみたいとは思いながらlxcやnutanix,proxmoxなどに浮気してみたり、忙しさにかまけていたらあっという間にもう5年もたってしまいました。

光陰矢の如しとはまさにこの事かと実感しています。

物事はなんでもやらなければ始まらないので、間隙を縫ってまずはminikubeでシングルノードローカルkubernetes環境の構築をしてみる事にしました。

今回環境を構築するのはAlmaLinux9.4で、minimalISOから最小構成でインストールし、一般ユーザyoyoを作成したところまでのものです。

[yoyo@AL ~]$ cat /etc/os-release
NAME="AlmaLinux"
VERSION="9.4 (Seafoam Ocelot)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
PRETTY_NAME="AlmaLinux 9.4 (Seafoam Ocelot)"
ANSI_COLOR="0;34"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
ALMALINUX_MANTISBT_PROJECT_VERSION="9.4"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.4"
SUPPORT_END=2032-06-01
[yoyo@ks1 ~]$ docker version
Client: Docker Engine - Community
 Version:           26.1.3
 API version:       1.45
 Go version:        go1.21.10
 Git commit:        b72abbb
 Built:             Thu May 16 08:35:29 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.3
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.10
  Git commit:       8e96db1
  Built:            Thu May 16 08:33:53 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.32
  GitCommit:        8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[yoyo@AL ~]$ minikube version
minikube version: v1.33.1
commit: 5883c09216182566a63dff4c326a6fc9ed2982ff
[yoyo@AL ~]$ kubectl version
Client Version: v1.30.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3

1.手順の概要

本稿は概ね以下の手順を行います。順番はいろいろと前後しても多分大丈夫ですが、この順番にやるのが一番きれいにできると思います。

  • docker
    • dockerリポジトリの追加
    • dockerのインストール
    • サービス開始と登録
    • dockerグループへユーザ登録
    • 再接続もしくは再起動
    • dockerの動作確認
  • kubectl
    • kubernetesリポジトリの追加
    • kubectlのインストール
  • minikube
    • minikubeのインストール
    • minikubeの起動
    • minikubeの状態確認
    • 動作確認

minikubeを動かすのにdockerを採用しています。

2.docker作業

予めrootユーザでログインしておきます。

su -

dockerリポジトリの追加

公式ドキュメントを読むとcentos用リポジトリを使うのがよさそうですが、rhel(s390x)リポジトリでも問題ないと思います。

この手順ではrhel(s390x)で実行していますが、centosリポジトリでも後続手順で動作する事を確認しています。

dnf install dnf-plugins-core -y
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

dockerのインストール

dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

サービス開始と登録

systemctl enable docker
systemctl start docker

dockerグループへユーザ登録

usermod -aG docker yoyo

再接続もしくは再起動

ユーザ設定を変更したのでbashの再読み込みが必要です。再起動するかいちどログアウトして再度ログインします。

reboot now

dockerの動作確認

一般ユーザでログインして以下コマンドを試します。

docker run hello-world

↓こんなのが表示されたら成功です。

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

3.kubectl作業

rootユーザに変更

su -

kubernetesリポジトリの追加

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/repodata/repomd.xml.key
EOF

kubectlのインストール

dnf install kubectl -y

4.minikube作業

minikubeのインストール

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
rpm -Uvh minikube-latest.x86_64.rpm

minikubeの起動

rootユーザから抜けて、一般ユーザで実行します。

minikube start

minikubeの状態確認

minikube status

ここまで問題なければローカルkubernetes環境の構築は終了です。

構築時に発生した事

構築時に公式手順の上から実行しましたが、ちょいちょいうまくいかなかったのっで、その時のメモのようなものです。同じようになった際のご参考になればと思います。

driverがない

dockerをインストールしないでkubectl,minikubeをインストールした時に出力。

minikube status

😄  minikube v1.33.1 on Almalinux 9.4 (hyperv/amd64)
👎  Unable to pick a default driver. Here is what was considered, in preference order:
💡  Alternatively you could install one of these drivers:
    ▪ docker: Not installed: exec: "docker": executable file not found in $PATH
    ▪ kvm2: Not installed: exec: "virsh": executable file not found in $PATH
    ▪ podman: Not installed: exec: "podman": executable file not found in $PATH
    ▪ qemu2: Not installed: exec: "qemu-system-x86_64": executable file not found in $PATH
    ▪ virtualbox: Not installed: unable to find VBoxManage in $PATH

❌  Exiting due to DRV_NOT_DETECTED: No possible driver was detected. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/

恐らくdocker,podman,kvm2,qemu2,virtualboxのいずれかがインストールされていないとダメ。

なので一般的なdockerを入れてみる事にする。

minikube startできない

ログがなくて申し訳ないのですが、minikube startができない事が2パターンありました。これは私の理解不足だったのですが、

  • dockerに割り当てるメモリが足りない(要はマシンのメモリ不足)
  • 実行権限の間違い(rootユーザではなく、dockerグループの一般ユーザで実行する必要があった)

という事でした。

うまくいかない場合は

  • メモリが不足していないか
  • 権限を付与しているか
  • 実行ユーザを間違えていないか

を確認すると良いかもしれません。

参考

https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
https://minikube.sigs.k8s.io/docs/start/?arch=%2Flinux%2Fx86-64%2Fstable%2Frpm+package
https://docs.docker.com/engine/install/rhel/#install-using-the-repository

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