LoginSignup
1
0

Fedora41を1台つかっておうちKubernetesを準備する

Last updated at Posted at 2024-05-21

前回の記事はこちら

やりたいこと

おうちKubernetesを準備したい!

Kubernetesがうごくまで

結論

結論だけ先に書きます。↓これだけです。

今回実行するコマンド全部
sudo dnf -y update
sudo dnf -y install kubernetes iproute-tc cri-o
sudo systemctl enable --now kubelet crio

sudo dnf -y remove zram-generator-defaults
sudo swapoff -a
sudo zramctl /dev/zram0 --reset

sudo modprobe br_netfilter
echo br_netfilter |sudo tee -a /etc/modules-load.d/br_netfilter.conf
printf '\nnet.bridge.bridge-nf-call-iptables=1\nnet.ipv4.ip_forward=1\n' |sudo tee -a /etc/sysctl.conf
sudo sysctl --system

sudo kubeadm init --v=5 --pod-network-cidr=10.244.0.0/16

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

kubectl taint node --all node-role.kubernetes.io/control-plane-
kubectl get cm -n kube-system coredns -o yaml |sed '/ loop/d' |kubectl apply -f -
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

説明

まず使うパッケージをインストールします。

sudo dnf -y update
sudo dnf -y install kubernetes iproute-tc cri-o

swap無効にします。

sudo dnf remove zram-generator-defaults
sudo swapoff -a
sudo zramctl /dev/zram0 --reset

ネットの設定を変えます。

sudo modprobe br_netfilter
echo br_netfilter |sudo tee /etc/modules-load.d/br_netfilter.conf
printf '\nnet.bridge.bridge-nf-call-iptables=1\nnet.ipv4.ip_forward=1\n' |sudo tee -a /etc/sysctl.conf
sudo sysctl --system

コンテナのサービスを有効にします。

sudo systemctl enable --now crio

kubeadmを初期化します。

sudo kubeadm init --v=5 --pod-network-cidr=10.244.0.0/16

しばらく放置すると↓こうなります。(こうなることを目指します)

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/

おとなしく言われたとおりにします。

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

Control planeにもスケジュールできるようにします。

kubectl taint nodes --all node-role.kubernetes.io/control-plane-

CoreDNSのloopが問題ありのようなので消します。

kubectl get cm -n kube-system coredns -o yaml |sed '/ loop/d' |kubectl apply -f -

定番のflannelをインストールします。

kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

確認

まずちゃんと動いてるか確認します。

kubectl get pods --all-namespaces
NAMESPACE      NAME                             READY   STATUS    RESTARTS   AGE
kube-flannel   kube-flannel-ds-7jgqk            1/1     Running   0          3m24s
kube-system    coredns-76f75df574-2v5g7         1/1     Running   0          3m24s
kube-system    coredns-76f75df574-vh4hf         1/1     Running   0          3m24s
kube-system    etcd-fedora                      1/1     Running   0          3m39s
kube-system    kube-apiserver-fedora            1/1     Running   0          3m38s
kube-system    kube-controller-manager-fedora   1/1     Running   0          3m40s
kube-system    kube-proxy-ztgxj                 1/1     Running   0          3m24s
kube-system    kube-scheduler-fedora            1/1     Running   0          3m35s

こんな感じでSTATUSのところが全部RunningになればOKです。

再起動して、もう一度上記コマンドでステータスを確認します。

手元の環境では全部Runningになりました。

やったね✨🎉🥳

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