markdown Raspberry Pi Kubernetes Cluster v1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Raspberry Pi Kubernetes Cluster v1相关的知识,希望对你有一定的参考价值。
# Raspberry Pi Kubernetes Cluster
## Hardware
- Four Raspberry Pi 3's
- TP-Link 8 Port Switch
- 6 Port USB Wall Charger
- Brass Spacer Standoff Assortment Kit
- Four Samsung 32GB MicroSD EVO Select Memory Cards
## Software
- Ansible installed on a control PC/Mac
- HypriotOS
- Kubectl installed on a control PC/Mac
- [Kube on Arm](https://github.com/lahsivjar/kube-arm)
## Steps
### Step 1: Flash all SD cards with the HypriotOS
Install the [HypriotOS Flash Tool](https://github.com/hypriot/flash). With that tool installed I flashed all 4 SD cards:
```
$ flash --hostname node01-red https://github.com/hypriot/image-builder-rpi/releases/download/v1.7.1/hypriotos-rpi-v1.7.1.img.zip
$ flash --hostname node02-blue https://github.com/hypriot/image-builder-rpi/releases/download/v1.7.1/hypriotos-rpi-v1.7.1.img.zip
$ flash --hostname node03-green https://github.com/hypriot/image-builder-rpi/releases/download/v1.7.1/hypriotos-rpi-v1.7.1.img.zi
$ flash --hostname node04-black https://github.com/hypriot/image-builder-rpi/releases/download/v1.7.1/hypriotos-rpi-v1.7.1.img.zip
```
### Prepare Raspberry Pi Nodes
With the SD Cards prepared I powered up the Pi's and logged in to each using the default user `pirate` and the default password `hypriot`. I then changed the file `/etc/network/interfaces.d/eth0` file to set a static IP on each of the nodes. In my case it looked like this:
```
node01-red 192.168.0.120
node02-blue 192.168.0.121
node03-green 192.168.0.122
node04-black 192.168.0.123
```
With the static IPs set I rebooted each instance and then copied my local SSH key to each node. This is needed for the Ansible playbook to run properly.
```
$ ssh-copy-id pirate@192.168.0.120
$ ssh-copy-id pirate@192.168.0.121
$ ssh-copy-id pirate@192.168.0.122
$ ssh-copy-id pirate@192.168.0.123
```
### Clone and edit Kubernetes on Arm Git Repo
We'll be using the a Git repo to deploy our Kubernetes cluster on the Pi's. First we need to clone the repo locally and update the `hosts.ini` file.
```
$ git clone https://github.com/lahsivjar/kube-arm.git
$ cd kube-arm
$ cp hosts_sample.ini hosts.ini
```
Open up the `hosts.ini` file and update it with the node names and IPs:
```
[kube-master]
# List of master nodes
node01-red ansible_host=192.168.0.120 ansible_user=pirate
[kube-workers]
# List of worker nodes
node02-blue ansible_host=192.168.0.121 ansible_user=pirate
node03-green ansible_host=192.168.0.122 ansible_user=pirate
node04-black ansible_host=192.168.0.123 ansible_user=pirate
[kube:children]
# Don't change this section
kube-master
kube-workers
[kube:vars]
# Node on which ingress controller will be deployed, if it is configured
# Remove this variable if ingress controller is not to be installed
ingress_controller_node=node02-blue
```
With the `hosts.ini` file updated we can run our the ansible playbook:
```
$ ansible-playbook -i hosts.ini cluster-init.yaml
```
The playbook will take about 5-10 minutes to complete. When it completes I grab the Kubernetes configuration file from the master node and export it so I can use `kubectl` on my Macbook to interact with the cluster.
```
$ scp 192.168.0.120:/home/pirate/.kube/config ~/homecluster.yml
$ export KUBECONFIG=/Users/ryan/homecluster.yml
```
With that all set I now test and make sure all nodes are online.
```
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
node01-red Ready master 10m v1.9.0
node02-blue Ready <none> 8m v1.9.0
node03-green Ready <none> 8m v1.9.0
node04-black Ready <none> 8m v1.9.0
```
## Pictures
![Cluster with Parts](https://dsc.cloud/quickshare/ClusterParts.jpg)
![Cluster with spacers](https://dsc.cloud/quickshare/ClusterWithSpacers.jpg)
![Cluster with colored network cables](https://dsc.cloud/quickshare/ClusterWithNetworkCables.jpg)
![Switch](https://dsc.cloud/quickshare/Switch.jpg)
![Cluster Version 1](https://dsc.cloud/quickshare/ClusterVersion1.jpg)
以上是关于markdown Raspberry Pi Kubernetes Cluster v1的主要内容,如果未能解决你的问题,请参考以下文章
markdown 在本地网络上查找Raspberry PI地址
markdown 在本地网络上查找Raspberry PI地址
markdown Raspberry Pi Kubernetes Cluster v1