https://wiki.archlinux.org/api.php?action=feedcontributions&user=Es02&feedformat=atomArchWiki - User contributions [en]2024-03-29T09:23:59ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=K8s&diff=573310K8s2019-05-16T01:24:46Z<p>Es02: --advertise-address is no longer a valid command. It has been replaced with --apiserver-advertise-address</p>
<hr />
<div>[[Category:Virtualization]]<br />
[[ja:Kubernetes]]<br />
[https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/ Kubernetes] is an open-source system for automating deployment, scaling, and management of containerized applications. Kubernetes is also referred to as k8s.<br />
<br />
== Kubernetes for Arch Linux ==<br />
<br />
There are several AUR packages for Kubernetes on Arch Linux:<br />
<br />
* {{AUR|kubernetes}}: It builds the go-source code of Kubernetes from the GitHub.<br />
<br />
* {{AUR|kubernetes-bin}}: It installs the pre-built binaries and configurations of the kubernetes package without requiring to build them.<br />
<br />
== Kubectl plugins for Arch Linux ==<br />
<br />
[https://kubernetes.io/docs/reference/kubectl/overview/ Kubectl] plugins are independent binaries that can be used to extend<br />
the Kubectl's functionalities by providing additional subcommands.<br />
<br />
There are AUR packages for Kubectl plugins on Arch Linux:<br />
<br />
* {{AUR|kubectl-trace-git}}: Schedule bpftrace programs on your kubernetes cluster using the kubectl.<br />
<br />
== Basic configuration ==<br />
<br />
You may either choose the {{ic|kubeadm}} helper or manually configuring a kubernetes cluster.<br />
<br />
=== Using kubeadm ===<br />
<br />
The following guide is for a one-master-one-slave build, where both nodes are in {{ic|192.168.122.0/24}} network and the master hosts the kubernetes cluster at {{ic|192.168.122.1}}. Note that pods have their own CIDR, assuming {{ic|192.168.123.0/24}} here.<br />
<br />
==== Master ====<br />
<br />
First, setup the configuration file for kubelet service,<br />
{{hc|/etc/kubernetes/kubelet|<br />
KUBELET_ARGS&#61;"--bootstrap-kubeconfig&#61;/etc/kubernetes/bootstrap-kubelet.conf \<br />
--kubeconfig&#61;/etc/kubernetes/kubelet.conf \<br />
--config&#61;/var/lib/kubelet/config.yaml \<br />
--network-plugin&#61;cni \<br />
--pod-infra-container-image&#61;k8s.gcr.io/pause:3.1"<br />
}}<br />
Don't worry for the not yet existing files in the arguments. They will be created during the {{ic|kubeadm}} initialization process. Note that if you are in a proxy environment or have special DNS settings, you should specify the {{ic|resolv.conf}} to be used in containers by adding one more argument<br />
{{bc|1=--resolv-conf=/the/path/to/the/resolv.conf}}<br />
<br />
Then, run<br />
{{bc|# kubeadm init --apiserver-advertise-address&#61;192.168.122.1 --pod-network-cidr&#61;192.168.123.0/24}}<br />
It will show the progress of initialization and stuck later, complaining about something like<br />
[kubelet-check] It seems like the kubelet isn't running or healthy.<br />
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.<br />
<br />
At this moment, [[start]] {{ic|kubelet.service}}. It is anticipated that kubelet will launch some kubernetes components, which will be confirmed by {{ic|kubeadm}}. If done successfully, there should be a message like:<br />
<br />
Your Kubernetes master has initialized successfully!<br />
<br />
Then you can configure your account as the administrator of this newly-created kubernetes cluster,<br />
<br />
$ mkdir -p $HOME/.kube<br />
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br />
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config<br />
<br />
Then you can deploy a pod network. Many choices can be found [https://kubernetes.io/docs/concepts/cluster-administration/addons/ here]. Note that all the options have their own default pod network CIDR. Thus, you should modify those settings according to what was given in {{ic|--pod-network-cidr}}.<br />
<br />
Finally, check the health of this master,<br />
$ kubectl get componentstatus<br />
<br />
==== Node ====<br />
<br />
Join the cluster by simply type in the final line of master's successful message,<br />
kubeadm join --token <token> 192.168.122.1:6443 --discovery-token-ca-cert-hash sha256:<hash><br />
<br />
== Trouble shooting ==<br />
<br />
=== settings behind proxy ===<br />
<br />
{{ic|kubeadm}} reads the {{ic|https_proxy}}, {{ic|http_proxy}}, and {{ic|no_proxy}} environment variables. Kubernetes internal networking should be included in the latest one, for example<br />
export no_proxy="192.168.122.0/24,10.96.0.0/12,192.168.123.0/24"<br />
where the second one is the default service network CIDR.<br />
<br />
You may also need extra CNI plugins<br />
$ go get -d github.com/containernetworking/plugins<br />
$ cd ~/go/src/github.com/containernetworking/plugins<br />
$ bash ./build_linux.sh <br />
# cp bin/* /opt/cni/bin/<br />
<br />
=== fatal error: runtime: out of memory ===<br />
This might happen when building kubernetes from source. A known trick is to setup a {{ic|zram}} region:<br />
# modprobe zram<br />
# echo lz4 > /sys/block/zram0/comp_algorithm<br />
# echo 16G > /sys/block/zram0/disksize<br />
# mkswap --label zram0 /dev/zram0<br />
# swapon --priority 100 /dev/zram0<br />
<br />
=== error when creating "xxx.yaml": No API token found for service account "default" ===<br />
Please check the details on [https://stackoverflow.com/questions/31891734/not-able-to-create-pod-in-kubernetes stackoverflow].<br />
<br />
=== Error: unable to load server certificate ===<br />
This might happen when start a service. Check if any of the {{ic|*.key}} files' permission setting is not appropriate.</div>Es02