RaspberryPi 4 に Kubernetes をインストールした。〜kubeadm編〜

はじめに

kubeadmを利用したシングルコントロールプレーン環境のインストール記録になります。kubernetsをインストールする前にDockerのインストールを行なっておく必要があります。

作業環境

・H/W : Raspberry Pi 4 x4 (Master x1 / Worker x3)
・OS : Ubuntu 18.04

1. Kubernetes インストール

作業はrootユーザーにて行なっていきます。

$ su 

# apt update && apt install -y apt-transport-https curl

# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
----
OK
----
   
# cat <<EOF | tee /etc/apt/sources.list.d/kubernetes.list
  deb https://apt.kubernetes.io/ kubernetes-xenial main
  EOF
------------------------------------------------------
deb https://apt.kubernetes.io/ kubernetes-xenial main
------------------------------------------------------
   
# apt update
# apt install -y kubelet kubeadm kubectl
# apt-mark hold kubelet kubeadm kubectl
-------------------------------------
kubelet set on hold.
kubeadm set on hold.
kubectl set on hold.
--------------------------------------

2. イニシャルセットアップ #Master Nodeのみ

Master Nodeでのみ実行します。
"--apiserver-advertise-address"にアドレス指定すると、指定したIPを利用してWorker Nodeとやりとりします。今回はeth0を指定しています。

# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.0.90
------------------------------------------------------------------------------------------
W0618 17:54:44.673685    3529 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[init] Using Kubernetes version: v1.18.4
[preflight] Running pre-flight checks
	[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/
[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 "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [wpfaros-mstr-001 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.0.90]
[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 [wpfaros-mstr-001 localhost] and IPs [192.168.0.90 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [wpfaros-mstr-001 localhost] and IPs [192.168.0.90 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"
W0618 17:56:33.920937    3529 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[control-plane] Creating static Pod manifest for "kube-scheduler"
W0618 17:56:33.924400    3529 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[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
[apiclient] All control plane components are healthy after 34.005081 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.18" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node wpfaros-mstr-001 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node wpfaros-mstr-001 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: py98zk.c9dgn0lit7ljckxj
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[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

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.0.90:6443 --token py98zk.c9dgn0lit7ljckxj \
   --discovery-token-ca-cert-hash sha256:0bd894fb7bffe1c1cb785f28ac31b7f8cd6f298c6598218ba8af411e6a2518b8
------------------------------------------------------------------------------------------

↑の標準出力結果に、Worker Node で実行するコマンドである "kubeadm join ..."の記載があります。後ほどworker-nodeで利用するので消さないでください。まずは一般ユーザーで "kubectl"コマンドが実行出来るようにコンフィグをコピーします。

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

# exit
  --> 一般ユーザーに戻る。
   
$ kubectl get node
------------------------------------------------------
NAME               STATUS    ROLES    AGE   VERSION
wpfaros-mstr-001   NotReady  master   10s   v1.18.4
------------------------------------------------------

次にpod間通信が出来るようにするため、flannelをデプロイします。

$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
--------------------------------------------------------------
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created --> 本当に必要なやつ
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created
---------------------------------------------------------------
こばなし。
flannelをいれるといくつか "daemonset.apps/kube-flannel-ds-..."というのがあり、これがCPUアーキテクチャを気にしないで動くようにしてくれてます。ラズパイ4だとarm64があれば他のdaemonsetはいらないです。後から消しても残しておいてもいいですが、僕はいらないものはゴミ箱に捨てるタイプなので、予めマニュフェストファイル(kube-flannel.yml)をダウンロードして不要な部分を削除しました。

3. ジョイン #Worker Nodeで作業

先ほど"Master Node"で出てきた"kubectl join ...." のコマンドを "Worker Node"で実行して、クラスターにジョインします。

$ sudo kubeadm join 192.168.0.90:6443 --token py98zk.c9dgn0lit7ljckxj \
>     --discovery-token-ca-cert-hash sha256:0bd894fb7bffe1c1cb785f28ac31b7f8cd6f298c6598218ba8af411e6a2518b8
------------------------------------------------------------------------------------------------------------
W0618 18:01:50.234135    4761 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
	[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/
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.18" ConfigMap in the kube-system namespace
[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...

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.
------------------------------------------------------------------------------------------------------------​

おわりに

"Master Node"で下記のコマンドを実行し、
各Nodeがクラスターに所属されていることを確認して完了です。

$ kubectl get nodes -o wide
----------------------------------------------------------------------------------------------------------------------------------------------
NAME               STATUS   ROLES    AGE     VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
wpfaros-mstr-001   Ready    master   9m38s   v1.18.4   192.168.0.90   <none>        Ubuntu 18.04.4 LTS   5.3.0-1027-raspi2   docker://19.3.11
wpfaros-node-001   Ready    <none>   4m33s   v1.18.4   192.168.0.91   <none>        Ubuntu 18.04.4 LTS   5.3.0-1027-raspi2   docker://19.3.11
wpfaros-node-002   Ready    <none>   3m13s   v1.18.4   192.168.0.92   <none>        Ubuntu 18.04.4 LTS   5.3.0-1027-raspi2   docker://19.3.11
wpfaros-node-003   Ready    <none>   107s    v1.18.4   192.168.0.93   <none>        Ubuntu 18.04.4 LTS   5.3.0-1027-raspi2   docker://19.3.11
----------------------------------------------------------------------------------------------------------------------------------------------

これでRaspberryPi4にKubernetesをインストールは完了です。
これだとただインストールしただけになってしまうので、色々と触っていきます。

cf.


この記事が気に入ったらサポートをしてみませんか?