😊

素のk8sをFedoraにインストール

に公開
2025/08/09

k8sをVMにインストールする手順
すんなり出来るかと思いきや、多少やることあったので備忘を兼ねて記載。

同じOSなら多分動くと思うので、コピペできるようにコマンドも記載。(こまいことは説明していない)

一部経緯を記載(エラーメッセージで検索したらひっかかるとうれしいと思って)

環境

  • OS: Fedora 42(Server)
  • Hyper-V上にVM構築
  • Memory: 最低4096MB
  • ネットワーク
    • Default Switch
    • 内部Switch
  • コンテナRuntime: containerd(Dockerは使わないのでインストールしません)
  • WorkerはControl planeと同居

内部SwitchはIP固定のため(DefaultはdhcpでIPが変わるのでめんどう)

OSインストール(k8s関係ないのでskip可)

まぁ適当に。

内部Switchをeth1にしたいので、Default SwitchだけでOSインストールして
インストール完了後、ネットワークを追加

IP固定のコマンド

nmcli connection mo
nmcli connection modify <uuid> con-name eth1
nmcli connection modify eth1 ipv4.addresses XXX.XXX.XXX.XXX/XX (お好きなIPに)
nmcli connection modify eth1 ipv4.method manual
nmcli connection modify eth1 connection.autoconnect yes

k8sインストール

前準備

sh -c 'echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.d/99-k8s.conf'
sudo systemctl stop firewalld
sudo systemctl disable firewalld

firewalldは必要なポートを開けるでもOK。試験環境なので、止めちゃう

kubeadm、kubelet、kubectlのインストール

公式に従ってインストール

RepositoryのURLが変わったようです。インストール手順には反映されていないんですが。。

ということで、以下はそれを反映したものになります。

k8sのバージョンを指定する必要があるので、ここで調べてURLに反映してください。

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl
EOF

setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

dnf install -y kubelet kubeadm kubectl

systemctl enable --now kubelet

k8sクラスタの作成

公式に従って実施。

kubeadm init --apiserver-advertise-address <内部Switch側のIP>192.168.137.3

この流れでinitをじっこうすると以下のようなエラーがでるかも。

[init] Using Kubernetes version: v1.33.3
[preflight] Running pre-flight checks
W0721 14:32:30.505939    2676 checks.go:1065] [preflight] WARNING: Couldn't create the interface used for talking to the container runtime: failed to create new CRI runtime service: validate service connection: validate CRI v1 runtime API for endpoint "unix:///var/run/containerd/containerd.sock": rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial unix /var/run/containerd/containerd.sock: connect: no such file or directory"
        [WARNING Swap]: swap is supported for cgroup v2 only. The kubelet must be properly configured to use swap. Please refer to https://kubernetes.io/docs/concepts/architecture/nodes/#swap-memory, or disable swap on the node
[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 beforehand using 'kubeadm config images pull'
error execution phase preflight: [preflight] Some fatal errors occurred:
failed to create new CRI runtime service: validate service connection: validate CRI v1 runtime API for endpoint "unix:///var/run/containerd/containerd.sock": rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial unix /var/run/containerd/containerd.sock: connect: no such file or directory"[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

端的に言えば、ランタイムが動いてないってことなので、以下コマンドでcontainerdを動かしてから再度init

systemctl start containerd
systemctl enable containerd

initをやり直したい場合は、 kubeadm reset を実行して再度initでOK

ここまではrootで作業。以降は、一般ユーザで必要に応じてsudoでOK

おそらくターミナルに表示されていると思うが、以下コマンドを実行して、contextを設定

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

以下のように、contextが表示されたら大丈夫

kubectl config get-context
CURRENT   NAME                          CLUSTER      AUTHINFO           NAMESPACE
*         kubernetes-admin@kubernetes   kubernetes   kubernetes-admin

kubectl config current-context
kubernetes-admin@kubernetes

その後の設定

多分以下のようになっていて、nodeがちゃんと動いていないはず

kubectl get nodes
NAME          STATUS     ROLES           AGE     VERSION
linux.local   NotReady   control-plane   4m21s   v1.33.2
kubectl get pods -A
NAMESPACE     NAME                                  READY   STATUS    RESTARTS   AGE
kube-system   coredns-674b8bbfcf-f9ggv              0/1     Pending   0          22m
kube-system   coredns-674b8bbfcf-pqb7c              0/1     Pending   0          22m
kube-system   etcd-linux.local                      1/1     Running   1          22m
kube-system   kube-apiserver-linux.local            1/1     Running   1          22m
kube-system   kube-controller-manager-linux.local   1/1     Running   1          22m
kube-system   kube-proxy-xwddq                      1/1     Running   0          22m
kube-system   kube-scheduler-linux.local            1/1     Running   1          22m

corednsがちゃんと動いていないのが原因。。。
describeしてみる

kubectl describe pod coredns-674b8bbfcf-f9ggv -n kube-system
  :(略)
Events:
  Type     Reason            Age                 From               Message
  ----     ------            ----                ----               -------
  Warning  FailedScheduling  117s (x5 over 23m)  default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {node.kubernetes.io/not-ready: }. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.

理由をちゃんと調べてないが、以下設定(☆の2行)を削除する

EDITOR=vi kubectl edit nodes

☆  - effect: NoSchedule
☆    key: node.kubernetes.io/not-ready

再びdescribe(ここでpod名が変わってるのは気にしないでください。。)

kubectl get pods -A
NAMESPACE     NAME                                  READY   STATUS              RESTARTS   AGE
kube-system   coredns-674b8bbfcf-pqb7c              0/1     ContainerCreating   0          30m
kube-system   coredns-674b8bbfcf-zfzk7              0/1     ContainerCreating   0          2m55s
kube-system   etcd-linux.local                      1/1     Running             1          30m
kube-system   kube-apiserver-linux.local            1/1     Running             1          30m
kube-system   kube-controller-manager-linux.local   1/1     Running             1          30m
kube-system   kube-proxy-xwddq                      1/1     Running             0          30m
kube-system   kube-scheduler-linux.local            1/1     Running             1          30m
kubectl describe pod -n kube-system   coredns-674b8bbfcf-pqb7c
  :(略)
Events:
  Type     Reason            Age                     From               Message
  ----     ------            ----                    ----               -------
  Warning  FailedScheduling  4m29s                   default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {node.kubernetes.io/not-ready: }. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
  Normal   Scheduled         3m47s                   default-scheduler  Successfully assigned kube-system/coredns-674b8bbfcf-zfzk7 to linux.local
  Warning  FailedMount       3m16s (x7 over 3m47s)   kubelet            MountVolume.SetUp failed for volume "config-volume" : object "kube-system"/"coredns" not registered
  Warning  NetworkNotReady   3m13s (x18 over 3m47s)  kubelet            network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized

CNI Pluginがインストールされてないから、起動に失敗。

CNIのインストール

CNIの非網羅的一覧(公式)
をみると色々あるが、今回はCiliumを使ってみる。

Flannelが有名っぽいが、特にCilium選定の理由はない。Graduatesしたって記事を見たからってだけ。。

ここの

  • Install the Cilium CLI
  • Install Cilium

をまずやる

Install the Cilium CLI

CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt)
CLI_ARCH=amd64
if [ "$(uname -m)" = "aarch64" ]; then CLI_ARCH=arm64; fi
curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
sha256sum --check cilium-linux-${CLI_ARCH}.tar.gz.sha256sum
sudo tar xzvfC cilium-linux-${CLI_ARCH}.tar.gz /usr/local/bin
rm cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}

Install Cilium

cilium install

特にバージョンは指定しないでインストール。インストールしたらPodを見てみる

kubectl get pods -A
NAMESPACE     NAME                                  READY   STATUS              RESTARTS   AGE
kube-system   cilium-envoy-vxvzd                    1/1     Running             0          97s
kube-system   cilium-hn8lp                          1/1     Running             0          97s
kube-system   cilium-operator-686959b66d-p924l      1/1     Running             0          97s
kube-system   coredns-674b8bbfcf-pqb7c              0/1     ContainerCreating   0          40m
kube-system   coredns-674b8bbfcf-zfzk7              0/1     ContainerCreating   0          12m
kube-system   etcd-linux.local                      1/1     Running             1          40m
kube-system   kube-apiserver-linux.local            1/1     Running             1          40m
kube-system   kube-controller-manager-linux.local   1/1     Running             1          40m
kube-system   kube-proxy-xwddq                      1/1     Running             0          40m
kube-system   kube-scheduler-linux.local            1/1     Running             1          40m

Cilium関連のPodが増えてる。ただ、corednsはまだ動ていていない。describe

Events:
  Type     Reason            Age                    From               Message
  ----     ------            ----                   ----               -------
  Warning  FailedScheduling  15m (x6 over 41m)      default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {node.kubernetes.io/not-ready: }. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
  Normal   Scheduled         13m                    default-scheduler  Successfully assigned kube-system/coredns-674b8bbfcf-pqb7c to linux.local
  Warning  FailedMount       13m (x7 over 13m)      kubelet            MountVolume.SetUp failed for volume "config-volume" : object "kube-system"/"coredns" not registered
  Warning  NetworkNotReady   3m34s (x301 over 13m)  kubelet            network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized

メッセージは変わっていないので、いったんPodをdeleteしてdescribeしてみる。

Events:
  Type     Reason                  Age   From               Message
  ----     ------                  ----  ----               -------
  Normal   Scheduled               17s   default-scheduler  Successfully assigned kube-system/coredns-674b8bbfcf-lrbcq to linux.local
  Warning  FailedCreatePodSandBox  17s   kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "bd0aa35cdb75f7ea624a24a213bcab9b1e8a145a572f4c4d5c7c357c365b4731": plugin type="cilium-cni" failed (add): failed to find plugin "cilium-cni" in path [/usr/libexec/cni/]
  Warning  FailedCreatePodSandBox  6s    kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "22d5aa6eedb3fe3b9fe0501a2f34d3036b02ff2a8eb8f984431a17ec6d51b478": plugin type="cilium-cni" failed (add): failed to find plugin "cilium-cni" in path [/usr/libexec/cni/]

メッセージが変わった。failed to find plugin "cilium-cni" in path [/usr/libexec/cni/] これが原因。

cilinum-cniコマンドは /opt/cni/bin にある。
インストール時にパスを指定するやり方がないか調べたが、見つからず。。。
シンボリックリンクで逃げる。

cd /usr/libexec/cni
sudo ln -s /opt/cni/bin/cilium-cni .
ls -l cilium-cni
lrwxrwxrwx. 1 root root      23  7月 21 15:24 cilium-cni -> /opt/cni/bin/cilium-cni

describeしてみる。

kubectl get pods -A
NAMESPACE     NAME                                  READY   STATUS    RESTARTS   AGE
kube-system   cilium-envoy-vxvzd                    1/1     Running   0          10m
kube-system   cilium-hn8lp                          1/1     Running   0          10m
kube-system   cilium-operator-686959b66d-p924l      1/1     Running   0          10m
kube-system   coredns-674b8bbfcf-lrbcq              1/1     Running   0          5m36s
kube-system   coredns-674b8bbfcf-zfzk7              1/1     Running   0          22m
kube-system   etcd-linux.local                      1/1     Running   1          49m
kube-system   kube-apiserver-linux.local            1/1     Running   1          49m
kube-system   kube-controller-manager-linux.local   1/1     Running   1          49m
kube-system   kube-proxy-xwddq                      1/1     Running   0          49m
kube-system   kube-scheduler-linux.local            1/1     Running   1          49m

動いた!!!

kubectl get nodes
NAME          STATUS   ROLES           AGE   VERSION
linux.local   Ready    control-plane   50m   v1.33.2

Nodeも動いているはず!

動作確認(しつつ最後の設定)

新規にNamespaceを作成して、その中にpodを立ててみる。

apiVersion: v1
kind: Namespace
metadata:
  name: test-ns
  labels:
    name: sample
---
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
  namespace: test-ns
spec:
  containers:
  - name: nginx
    image: nginx

上記内容を適当なファイルに書いて、kubectl apply -f <ファイル名> でクラスタに適用してみる。

kubectl get ns
NAME              STATUS   AGE
cilium-secrets    Active   19m
default           Active   57m
kube-node-lease   Active   57m
kube-public       Active   57m
kube-system       Active   57m
test-ns           Active   5s

Namespace OK

get pods -n test-ns
NAME       READY   STATUS    RESTARTS   AGE
test-pod   0/1     Pending   0          2m35s

いつものdescribe

Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  35s   default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.

Control planeにpodを立てられないようにtaintしている設定のため、動かない。

EDITOR=vi kubectl edit nodes
☆  - effect: NoSchedule
☆    key: node-role.kubernetes.io/control-plane

☆の2行を削除する。 taints: は残しておいてもOK。get podしてみる。

以下でもできるっぽい(再起動したらうまくいかず、以下3つ実行してさらに再起動したらできた。。)

kubectl taint nodes linux.local node-role.kubernetes.io/control-plane:NoSchedule-
kubectl taint node linux.local node-role.kubernetes.io/master:NoSchedule-
kubectl taint nodes linux.local node.kubernetes.io/unreachable:NoSchedule-
kubectl get pods -n test-ns
NAME       READY   STATUS    RESTARTS   AGE
test-pod   1/1     Running   0          5m27s

無事Running。

これで構築は完了です。お疲れさまでした

Discussion