In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to build a multi-node K8S cluster on the raspberry pie, which is very detailed and has a certain reference value. Interested friends must finish reading it!
Preparation in advance
To create the Kubernetes cluster in this article, we need to prepare:
At least one raspberry pie (with SD card and power adapter)
Ethernet cable
A switch or router that connects all our raspberry pies
I will install K3s from the network, so I need to access the Internet through the router.
Cluster architecture
For this cluster, we will use three raspberry pies. The first raspberry pie I named it kmaster and assigned a static IP of 192.168.0.50 (because my local network is 192.168.0.0amp 24). The first worker node (that is, the second Pi), we call it knode1 and assign IP 192.168.0.51. The last worker node, which we call knode2 and assigns IP 192.168.0.52.
Of course, if your network is different from mine, you can use it and you can get the network IP. Just replace your own value anywhere in this article using IP.
Instead of referencing each node through IP, we add its hostname to the / etc / hosts file on PC.
Echo-e "192.168.0.50\ tkmaster" | sudo tee-a / etc/hostsecho-e "192.168.0.51\ tknode1" | sudo tee-a / etc/hostsecho-e "192.168.0.52\ tknode2" | sudo tee-a / etc/hosts install master node
Now we are ready to install the master node. Step one, install the latest Raspbian image. I have written a detailed article about why the latest image is needed. Interested friends can check it in the link:
Https://carpie.net/articles/headless-pi-with-static-ip-wired-edition
Next, start installing Raspbian, enable SSH server, set the host name for kmaster, and assign the static IP 192.168.0.50.
Now that Raspbian is installed on the master node, let's enable our master Pi and enter it through ssh:
Ssh pi@kmaster
Now we are going to install K3s. Run on master Pi:
Curl-sfL https://get.k3s.io | sh-
After the command is executed, we have a single-node cluster that has been set up and is running! Let's check it out. Still on this Pi, run:
Sudo kubectl get nodes
You should see something like this:
Extraction of join token by NAME STATUS ROLES AGE VERSIONkmaster Ready master 2m13s v1.14.3-k3s.1
We want to add a pair of worker nodes. To install K3s on these nodes, we need a join token. Join token exists on the file system of the master node. Let's copy it and save it somewhere, and we can get it later:
Sudo cat / var/lib/rancher/k3s/server/node-token install worker node
Get some SD cards for both worker nodes and install Raspbian on each node. For one of them, set the hostname to knode1 and assign IP 192.168.0.51. For the other, set the hostname to knode2 and assign IP 192.168.0.52. Now, let's install K3s.
Start your first worker node and enter it through ssh:
Ssh pi@knode1
On this Pi, we will install K3s as before, but we will give the installer additional parameters to let it know that we are installing a worker node and are joining an existing cluster:
Curl-sfL http://get.k3s.io | K3Selecurl = https://192.168.0.50:6443\ K3S_TOKEN=join_token_we_copied_earlier sh-
Replace the join_token_we_copied_earlier with the join token extracted from the previous section. Repeat these steps for knode2.
Access the cluster from our PC
Whenever we want to check or modify the cluster, we have to run kubectl through the SSH to the master node, which is annoying. So, we want to put kubectl on our PC, but first let's get the configuration information we need from the master node. Enter kmaster through SSH and run:
Sudo cat / etc/rancher/k3s/k3s.yaml
Copy the configuration information and return to your PC. Create a directory for the configuration:
Mkdir / .kube
Save the copied configuration as ~ / .kube / config. Now edit the file and change:
Server: https://localhost:6443
Change to:
Server: https://kmaster:6443
For security reasons, limit read / write access to the file to yourself:
Chmod 600 ~ / .kube/config
Now let's install kubectl on our PC (if you haven't already). Instructions for doing this for various platforms are available on the Kubernetes website. Since I am running Linux Mint (a Ubuntu derivative), I will display a description of Ubuntu here:
Sudo apt update & & sudo apt install-y apt-transport-httpscurl-s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add-echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" |\ sudo tee-a / etc/apt/sources.list.d/kubernetes.listsudo apt update & & sudo apt install kubectl
If you're not familiar with it, the above command adds a Debian repository for Kubernetes, gets its GPG key for security, then updates the package list and installs kubectl. Now, I will be notified of kubectl updates through the standard software update mechanism.
Now we can check our cluster from our PC and run:
Kubectl get nodes
You should see something like this:
NAME STATUS ROLES AGE VERSIONkmaster Ready master 12m v1.14.3-k3s.1knode1 Ready worker 103s v1.14.3-k3s.1knode1 Ready worker 103s v1.14.3-k3s.1
Congratulations! You now have a working 3-node Kubernetes cluster!
Additional bonus using K3s
If you run kubectl get pods-all-namespaces, you will see some extra pod for Traefik. Treafik is a reverse proxy and load balancer that we can use to direct traffic to our cluster from a single entry point. Kubernetes can also install Traefik, but it is not provided by default. So providing Traefik by default in K3s is a great design!
These are all the contents of the article "how to build a multi-node K8S cluster on raspberry pie". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.