Install k8s on Raspberry pi 3 === 2019/4/27 # Introduction PC: Master Raspberry: Worker ## Prepaer Tools * flash tool [Etcher](https://www.balena.io/etcher/) * Image [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) * Install k8s script [alexellis/k8s-on-raspbian](https://raw.githubusercontent.com/alexellis/k8s-on-raspbian/master/script/prep.sh) --- # build k8s cluster step ## Flash image The flash step that using **etcher** : 1. Download **Etcher** and install it. 2. Connect an SD card reader with the SD card inside. 3. Open Etcher and select from your hard drive the Raspberry Pi `.img` or `.zip` file you wish to write to the SD card. 4. Select the SD card you wish to write your image to. 5. Review your selections and click 'Flash!' to begin writing data to the SD card. Default Account User: `pi` password: `raspberry` > default enabled `ssh` > >write ssh file to boot volume > >ex: touch /Volumes/boot/ssh ref: * [Installation Guide](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) ## Configure WiFi setup `ssh`, `language` and `WiFi` by `raspi-config` `sudo raspi-config` ### enable SSH 1. 5 Interfacing Options 2. P2 SSH 3. YES 4. reboot ### setting language 1. 4 Localisation Options 2. I1 Change Locale 3. select `[*] zh_TW.UTF-8 UTF-8` 4. NONE ### setting wifi 1. 2 Network Options 2. N2 Wi-fi 3. input your SSID 4. input your password ## Install docker, kubeadm ``` curl https://raw.githubusercontent.com/alexellis/k8s-on-raspbian/master/script/prep.sh > ~/install_script.sh sudo bash ~/install_script.sh sudo reboot ``` ref: * [alexellis/k8s-on-raspbian](https://github.com/alexellis/k8s-on-raspbian) ## Create k8s cluster in Master PC * network using Weave(or flannel) 1. `sudo kubeadm init` ```shell= Your Kubernetes master 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: /docs/concepts/cluster-administration/addons/ You can now join any number of machines by running the following on each node as root: kubeadm join <master-ip>:<master-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash> ``` 2. `kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"` P.S. this is my using script ``` sudo swapoff -a && sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-cert-extra-sans=sian-home.ddns.net ``` ref: * [create-cluster-kubeadm](https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/) ## Join Raspberry Pi to Closter 1. `kubeadm join <master-ip>:<master-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>` ## Completed * label rapsberry to worker `kubectl label node raspberrypi node-role.kubernetes.io/worker=worker` * take off `taint` `kubectl taint nodes --all node-role.kubernetes.io/master-` * check nodes are `ready` state `kubectl get nodes -o wide` ``` NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME raspberrypi Ready worker 9h v1.14.1 192.168.1.179 <none> Raspbian GNU/Linux 9 (stretch) 4.14.98-v7+ docker://18.9.0 sian Ready master 9h v1.14.1 36.236.142.127 <none> Ubuntu 16.04.6 LTS 4.15.0-47-generic docker://18.6.2 ``` * check pods are `Running` `kubectl get pods --all-namespaces` ```  NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kube-system coredns-fb8b8dccf-9nxf9 1/1 Running 0 9h 10.244.0.3 sian <none> <none> kube-system coredns-fb8b8dccf-dlc7v 1/1 Running 0 9h 10.244.0.2 sian <none> <none> kube-system etcd-sian 1/1 Running 0 9h 36.236.142.127 sian <none> <none> kube-system kube-apiserver-sian 1/1 Running 0 9h 36.236.142.127 sian <none> <none> kube-system kube-controller-manager-sian 1/1 Running 0 9h 36.236.142.127 sian <none> <none> kube-system kube-flannel-ds-amd64-6kgjq 1/1 Running 0 9h 36.236.142.127 sian <none> <none> kube-system kube-flannel-ds-arm-jzlz5 1/1 Running 1 9h 192.168.1.179 raspberrypi <none> <none> kube-system kube-proxy-lbmwn 1/1 Running 1 9h 192.168.1.179 raspberrypi <none> <none> kube-system kube-proxy-pgz42 1/1 Running 0 9h 36.236.142.127 sian <none> <none> kube-system kube-scheduler-sian 1/1 Running 0 9h 36.236.142.127 sian <none> <none> ``` # TBD * [wireguard VPN](https://www.wireguard.com/quickstart/) # Troubleshooting ## coredns crash Q: Check nameserver is `127.0.0.1` in `/etc/resolv.conf` A: `vi /etc/resolv.conf` ``` # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 8.8.8.8 ``` ###### tags: `Raspberry Pi` `k8s` `IoT`