ぴよ丸水産

週末ファゴッティストによる技術ブログ

【Kubernetes】CentOS8環境にMinikubeをインストール

はじめに

大学生から使っていたポンコツPC(Windows)にCentOS8を入れ、
勉強用マシンとして再生させました。

Kubernetes勉強用にMinikubeをインストールしたので、
構築メモを残しておこうと思います。
とりあえずローカルからダッシュボードが見れるところまでできました。

環境

項目
OS CentOS8.2.2004
Minikube v1.12.0
Kubernetes v1.18.3
Docker 19.03.12

構築手順

Dockerをインストール

qiita.com 上記の記事を参考にしました。

# dnf update -y
# dnf repolist
repo id                            repo の名前
AppStream                          CentOS-8 - AppStream
BaseOS                             CentOS-8 - Base
extras                             CentOS-8 - Extras
# dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
repo の追加: https://download.docker.com/linux/centos/docker-ce.repo
# dnf repolist
repo id                             repo の名前
AppStream                           CentOS-8 - AppStream
BaseOS                              CentOS-8 - Base
docker-ce-stable                    Docker CE Stable - x86_64
extras                              CentOS-8 - Extras

そのままdnf -y install docker-ce docker-ce-cli containerd.ioを実行すると、
参考記事と同様にcontainerd.ioのバージョンについてのエラーが出てきます。
CentOS8ではcontainerd.io >= 1.2.2-3がまだ提供されていないからのようです。
rpmを落としてきてインストールしておきます。
前述のコマンドに-nobestオプションをつけてもいけるようです。

# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.2-3.3.el7.x86_64.rpm
--2020-07-12 06:09:22--  https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.2-3.3.el7.x86_64.rpm
download.docker.com (download.docker.com) をDNSに問いあわせています... 99.86.193.61, 99.86.193.20, 99.86.193.109, ...
download.docker.com (download.docker.com)|99.86.193.61|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 23159364 (22M) [application/x-redhat-package-manager]
`containerd.io-1.2.2-3.3.el7.x86_64.rpm' に保存中

containerd.io-1.2.2 100%[===================>]  22.09M  2.11MB/s 時間 10s      

2020-07-12 06:09:33 (2.15 MB/s) - `containerd.io-1.2.2-3.3.el7.x86_64.rpm' へ保存完了 [23159364/23159364]

# dnf install containerd.io-1.2.2-3.3.el7.x86_64.rpm
メタデータの期限切れの最終確認: 0:01:25 時間前の 2020年07月12日 06時08分57秒 に実施しました。
依存関係が解決しました。
================================================================================
 パッケージ          Arch         バージョン           リポジトリー       サイズ
================================================================================
インストール中:
 containerd.io       x86_64       1.2.2-3.3.el7        @commandline        22 M
     置き換え  runc.x86_64 1.0.0-65.rc10.module_el8.2.0+305+5e198a41

トランザクションの概要
================================================================================
インストール  1 パッケージ

合計サイズ: 22 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備              :                                                       1/1 
  インストール中    : containerd.io-1.2.2-3.3.el7.x86_64                    1/2 
  scriptlet の実行中: containerd.io-1.2.2-3.3.el7.x86_64                    1/2 
  廃止              : runc-1.0.0-65.rc10.module_el8.2.0+305+5e198a41.x86_   2/2 
  scriptlet の実行中: runc-1.0.0-65.rc10.module_el8.2.0+305+5e198a41.x86_   2/2 
  検証              : containerd.io-1.2.2-3.3.el7.x86_64                    1/2 
  検証              : runc-1.0.0-65.rc10.module_el8.2.0+305+5e198a41.x86_   2/2 
Installed products updated.

インストール済み:
  containerd.io-1.2.2-3.3.el7.x86_64                                            

完了しました!
# dnf install -y docker-ce docker-ce-cli
メタデータの期限切れの最終確認: 0:01:46 時間前の 2020年07月12日 06時08分57秒 に実施しました。
依存関係が解決しました。
================================================================================
 パッケージ        Arch       バージョン             リポジトリー         サイズ
================================================================================
インストール中:
 docker-ce         x86_64     3:19.03.12-3.el7       docker-ce-stable      24 M
 docker-ce-cli     x86_64     1:19.03.12-3.el7       docker-ce-stable      38 M
依存関係のインストール中:
 libcgroup         x86_64     0.41-19.el8            BaseOS                70 k

トランザクションの概要
================================================================================
インストール  3 パッケージ

ダウンロードサイズの合計: 62 M
インストール済みのサイズ: 263 M
パッケージのダウンロード:
(1/3): libcgroup-0.41-19.el8.x86_64.rpm         307 kB/s |  70 kB     00:00    
(2/3): docker-ce-19.03.12-3.el7.x86_64.rpm      1.4 MB/s |  24 MB     00:17    
(3/3): docker-ce-cli-19.03.12-3.el7.x86_64.rpm  1.2 MB/s |  38 MB     00:32    
--------------------------------------------------------------------------------
合計                                            1.9 MB/s |  62 MB     00:33     
警告: /var/cache/dnf/docker-ce-stable-091d8a9c23201250/packages/docker-ce-19.03.12-3.el7.x86_64.rpm: ヘッダー V4 RSA/SHA512 Signature、鍵 ID 621e9f35: NOKEY
Docker CE Stable - x86_64                       5.8 kB/s | 1.6 kB     00:00    
GPG 鍵 0x621E9F35 をインポート中:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://download.docker.com/linux/centos/gpg
鍵のインポートに成功しました
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備              :                                                       1/1 
  インストール中    : docker-ce-cli-1:19.03.12-3.el7.x86_64                 1/3 
  scriptlet の実行中: docker-ce-cli-1:19.03.12-3.el7.x86_64                 1/3 
  scriptlet の実行中: libcgroup-0.41-19.el8.x86_64                          2/3 
  インストール中    : libcgroup-0.41-19.el8.x86_64                          2/3 
  scriptlet の実行中: libcgroup-0.41-19.el8.x86_64                          2/3 
  インストール中    : docker-ce-3:19.03.12-3.el7.x86_64                     3/3 
  scriptlet の実行中: docker-ce-3:19.03.12-3.el7.x86_64                     3/3 
  検証              : libcgroup-0.41-19.el8.x86_64                          1/3 
  検証              : docker-ce-3:19.03.12-3.el7.x86_64                     2/3 
  検証              : docker-ce-cli-1:19.03.12-3.el7.x86_64                 3/3 
Installed products updated.

インストール済み:
  docker-ce-3:19.03.12-3.el7.x86_64    docker-ce-cli-1:19.03.12-3.el7.x86_64   
  libcgroup-0.41-19.el8.x86_64        

完了しました!

Minikubeのインストール

Minikubeをインストールします。

# curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 54.9M  100 54.9M    0     0  2783k      0  0:00:20  0:00:20 --:--:-- 3640k

kube-ctlをインストールします。

# curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 41.9M  100 41.9M    0     0  1708k      0  0:00:25  0:00:25 --:--:-- 1824k

環境変数を/etc/profileに定義します。

# vi /etc/profile

下記の定義を追加します。

export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=/root
export CHANGE_MINIKUBE_NONE_USER=true
export KUBECONFIG=/root/.kube/config

/root/.kube/configを作成します。

# mkdir -p /root/.kube || true
# touch /root/.kube/config

Minikubeの起動!

# /usr/local/bin/minikube start --vm-driver=none
😄  Centos 8.2.2004 上の minikube v1.12.0
✨  設定を元に、 none ドライバを使用します
💣  Sorry, Kubernetes 1.18.3 requires conntrack to be installed in root's path

おや。。。 conntrackがないよと言われたので、インストールします。

# dnf install conntrack
メタデータの期限切れの最終確認: 0:07:56 時間前の 2020年07月12日 06時08分57秒 に実施しました。
依存関係が解決しました。
================================================================================
 パッケージ                  Arch        バージョン           Repo        サイズ
================================================================================
インストール中:
 conntrack-tools             x86_64      1.4.4-10.el8         BaseOS      204 k
依存関係のインストール中:
 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.2-11.el8         BaseOS       30 k

トランザクションの概要
================================================================================
インストール  4 パッケージ

ダウンロードサイズの合計: 282 k
インストール済みのサイズ: 699 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/4): libnetfilter_cttimeout-1.0.0-11.el8.x86_  80 kB/s |  24 kB     00:00    
(2/4): libnetfilter_cthelper-1.0.0-15.el8.x86_6  67 kB/s |  24 kB     00:00    
(3/4): libnetfilter_queue-1.0.2-11.el8.x86_64.r 100 kB/s |  30 kB     00:00    
(4/4): conntrack-tools-1.4.4-10.el8.x86_64.rpm  314 kB/s | 204 kB     00:00    
--------------------------------------------------------------------------------
合計                                            189 kB/s | 282 kB     00:01     
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備              :                                                       1/1 
  インストール中    : libnetfilter_queue-1.0.2-11.el8.x86_64                1/4 
  scriptlet の実行中: libnetfilter_queue-1.0.2-11.el8.x86_64                1/4 
  インストール中    : libnetfilter_cttimeout-1.0.0-11.el8.x86_64            2/4 
  scriptlet の実行中: libnetfilter_cttimeout-1.0.0-11.el8.x86_64            2/4 
  インストール中    : libnetfilter_cthelper-1.0.0-15.el8.x86_64             3/4 
  scriptlet の実行中: libnetfilter_cthelper-1.0.0-15.el8.x86_64             3/4 
  インストール中    : conntrack-tools-1.4.4-10.el8.x86_64                   4/4 
  scriptlet の実行中: conntrack-tools-1.4.4-10.el8.x86_64                   4/4 
  検証              : conntrack-tools-1.4.4-10.el8.x86_64                   1/4 
  検証              : libnetfilter_cthelper-1.0.0-15.el8.x86_64             2/4 
  検証              : libnetfilter_cttimeout-1.0.0-11.el8.x86_64            3/4 
  検証              : libnetfilter_queue-1.0.2-11.el8.x86_64                4/4 
Installed products updated.

インストール済み:
  conntrack-tools-1.4.4-10.el8.x86_64                                           
  libnetfilter_cthelper-1.0.0-15.el8.x86_64                                     
  libnetfilter_cttimeout-1.0.0-11.el8.x86_64                                    
  libnetfilter_queue-1.0.2-11.el8.x86_64                                        

完了しました!

これでOKかと、、 Minikubeの起動リトライ!

# /usr/local/bin/minikube start --vm-driver=none
😄  Centos 8.2.2004 上の minikube v1.12.0
✨  設定を元に、 none ドライバを使用します
👍  Starting control plane node minikube in cluster minikube
🤹  Running on localhost (CPUs=2, Memory=3659MB, Disk=51175MB) ...
ℹ️  OS は CentOS Linux 8 (Core) です。
🐳  Docker 19.03.12 で Kubernetes v1.18.3 を準備しています...
    > kubelet.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubectl.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm: 37.97 MiB / 37.97 MiB [---------------] 100.00% 2.52 MiB p/s 15s
    > kubectl: 41.99 MiB / 41.99 MiB [-------------] 100.00% 956.85 KiB p/s 45s
    > kubelet: 108.04 MiB / 108.04 MiB [-------------] 100.00% 1.99 MiB p/s 54s
💥  初期化が失敗しました。再施行します。 run: /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.18.3:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap": exit status 1
stdout:
[init] Using Kubernetes version: v1.18.3
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[certs] Using certificateDir folder "/var/lib/minikube/certs"
[certs] Using existing ca certificate authority
[certs] Using existing apiserver certificate and key on disk
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [piyohost localhost] and IPs [192.168.10.3 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [piyohost localhost] and IPs [192.168.10.3 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.

    Unfortunately, an error has occurred:
        timed out waiting for the condition

    This error is likely caused by:
        - The kubelet is not running
        - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

    If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
        - 'systemctl status kubelet'
        - 'journalctl -xeu kubelet'

    Additionally, a control plane component may have crashed or exited when started by the container runtime.
    To troubleshoot, list all containers using your preferred container runtimes CLI.

    Here is one example how you may list all Kubernetes containers running in docker:
        - 'docker ps -a | grep kube | grep -v pause'
        Once you have found the failing container, you can inspect its logs with:
        - 'docker logs CONTAINERID'


stderr:
W0712 06:18:46.402114   63103 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
    [WARNING Firewalld]: firewalld is active, please ensure ports [8443 10250] are open or your cluster may not function correctly
    [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
    [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
    [WARNING Swap]: running with swap on is not supported. Please disable swap
    [WARNING FileExisting-socat]: socat not found in system path
    [WARNING Hostname]: hostname "piyohost" could not be reached
    [WARNING Hostname]: hostname "piyohost": lookup piyohost on 192.168.10.1:53: no such host
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
W0712 06:21:17.837160   63103 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
W0712 06:21:17.839148   63103 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

上記のエラーはSELinuxを無効にすると解決しました。 (このあと/etc/selinux/config も書き換えておきました。)

# getenforce
Enforcing
# setenforce 0
# getenforce
Permissive

Minikubeの起動リトライ!

# /usr/local/bin/minikube start --vm-driver=none
😄  Centos 8.2.2004 上の minikube v1.12.0
✨  プロフィールを元に、 none ドライバを使用します
👍  Starting control plane node minikube in cluster minikube
🏃  Updating the running none "minikube" bare metal machine ...
ℹ️  OS は CentOS Linux 8 (Core) です。
🐳  Docker 19.03.12 で Kubernetes v1.18.3 を準備しています...
🤦  Unable to restart cluster, will reset it: getting k8s client: client config: client config: context "minikube" does not exist
🤹  Configuring local host environment ...

❗  The 'none' driver is designed for experts who need to integrate with an existing VM
💡  Most users should use the newer 'docker' driver instead, which does not require root!
📘  For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/

❗  kubectl と minikube の構成は /root に保存されます
❗  kubectl か minikube コマンドを独自のユーザーとして使用するには、そのコマンドの再配置が必要な場合があります。たとえば、独自の設定を上書きするには、以下を実行します

    ▪ sudo mv /root/.kube /root/.minikube $HOME
    ▪ sudo chown -R $USER $HOME/.kube $HOME/.minikube

💡  これは環境変数 CHANGE_MINIKUBE_NONE_USER=true を設定して自動的に行うこともできます
🔎  Verifying Kubernetes components...
🌟  Enabled addons: default-storageclass, storage-provisioner
🏄  Done! kubectl is now configured to use "minikube"

無事起動しました。

# minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

ダッシュボードにアクセス

ダッシュボードを起動します。

minikube dashboard --url &
[1] 88067
# 🤔  ダッシュボードの状態を確認しています...
🚀  プロキシを起動しています...
🤔  プロキシの状態を確認しています...
http://127.0.0.1:37507/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

f:id:blue-38:20200712165707p:plain

おわりに

とりあえず今日はダッシュボード見て満足して終わります。 podやdeploymentについてはまた次回…

参考

qiita.com