是的 - 您可以使用 Raspberry Pi 默认的 Raspbian 操作系统,创建 Kubernetes 集群。 将您习惯的所有工具和软件包,与官方支持的操作系统一起使用。
1.烧录 Raspbian 到一个新的 SD 卡
您可以使用 Etcher.io 来烧录 SD 卡。
在启动之前,在 SD 卡的 /boot/
中创建一个名为 ssh 的空文件,以启用 SSH。
使用 Raspbian Jessie,下载地址:https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-07-05/
2.修改 hostname
使用 raspi-config
实用程序将主机名更改为 k8s-master-1
或类似名称,然后重新启动。
3.安装Docker
它将安装 Docker 17.05 - Jessie的最新版本。
$ curl -sSL get.docker.com | sh && \
sudo usermod pi -aG docker
4.禁止swap(交换空间)
对于Kubernetes 1.7和更新版本,如果启用了交换空间,将会出现错误。
关掉 swap:
$ sudo dphys-swapfile swapoff && \
sudo dphys-swapfile uninstall && \
sudo update-rc.d dphys-swapfile remove
现在应该显示没有条目:
$ sudo swapon --summary
5.编辑/boot/cmdline.txt
在该行的末尾添加此文本,但不要创建任何新行:
cgroup_enable=cpuset cgroup_enable=memory
现在重新启动 - 不要跳过这一步。
6.添加源列表 & 安装 kubeadm
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && \
sudo apt-get update -q && \
sudo apt-get install -qy kubeadm
我意识到这个在 apt 列出(listing)中说的 'xenial',别担心。 它仍然有效。
您现在已经安装了两个新的命令:
7.初始化您的主节点
$ sudo kubeadm init
也可以通过
--apiserver-advertise-address=192.168.0.27
与 Pi 的 IP。
注意
:这一步将需要很长时间,甚至长达 15 分钟。
在 init
完成之后,运行在命令行中给出的代码片段:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
8.现在保存你的连接令牌
您的连接令牌有效期为24小时,因此请将其保存到文本文件中。 这是我的一个例子:
$ kubeadm join --token 9e700f.7dc97f5e3a45c9e5 192.168.0.27:6443 --discovery-token-ca-cert-hash sha256:95cbb9ee5536aa61ec0239d6edd8598af68758308d0a0425848ae1af28859bea
9.检查一切工作
$ kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
etcd-of-2 1/1 Running 0 12m
kube-apiserver-of-2 1/1 Running 2 12m
kube-controller-manager-of-2 1/1 Running 1 11m
kube-dns-66ffd5c588-d8292 3/3 Running 0 11m
kube-proxy-xcj5h 1/1 Running 0 11m
kube-scheduler-of-2 1/1 Running 0 11m
weave-net-zz9rz 2/2 Running 0 5m
你应该看到上面所有服务的 “READY” 计数显示为1/1。DNS 使用三个 pods,所以你会看到 3/3。
10.设置网络
安装 Weave 网络驱动程序:
$ kubectl apply -f https://git.io/weave-kube-1.6
在另一个 Raspberry Pi 上,除了 kubeadm init
之外,再重复一遍。
1.更改主机名
使用 raspi-config
实用程序将主机名更改为 k8s-worker-1
或类似名称,然后重新启动。
2.加入集群
替换您从主节点获得的输出的令牌/IP:
$ sudo kubeadm join --token 1fd0d8.67e7083ed7ec08f3 192.168.0.27:6443
现在,你可以在 master 上运行这个:
$ kubectl get nodes
NAME STATUS AGE VERSION
k8s-1 Ready 5m v1.7.4
k8s-2 Ready 10m v1.7.4
function.yml
代码如下:
apiVersion: v1
kind: Service
metadata:
name: markdownrender
labels:
app: markdownrender
spec:
type: NodePort
ports:
- port: 8080
protocol: TCP
targetPort: 8080
nodePort: 31118
selector:
app: markdownrender
---
apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
kind: Deployment
metadata:
name: markdownrender
spec:
replicas: 1
template:
metadata:
labels:
app: markdownrender
spec:
containers:
- name: markdownrender
image: functions/markdownrender:latest-armhf
imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
部署和测试:
$ kubectl create -f function.yml
$ curl -4 http://localhost:31118 -d "# test"
<p><h1>test</h1></p>
从您的笔记本电脑等远程机器,使用您的 Kubernetes 主机的 IP 地址,并再次尝试相同的设置。
这是开发仪表板,其 TLS 被禁用,更容易使用。
$ curl -sSL https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard-arm.yaml | kubectl create -f -
然后你可以通过 kubectl get svc -n kube-system
找到 IP 和端口。 要从您的笔记本电脑访问此,您将需要使用 kubectl proxy
。
现在在 Kubernetes master 上移除测试部署:
$ kubectl delete -f function.yml
Raspberry Pi 的准备脚本如下所示:
#!/bin/sh
# This installs the base instructions up to the point of joining / creating a cluster
curl -sSL get.docker.com | sh && \
sudo usermod pi -aG docker
sudo dphys-swapfile swapoff && \
sudo dphys-swapfile uninstall && \
sudo update-rc.d dphys-swapfile remove
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && \
sudo apt-get update -q && \
sudo apt-get install -qy kubeadm
echo Adding " cgroup_enable=cpuset cgroup_enable=memory" to /boot/cmdline.txt
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
orig="$(head -n1 /boot/cmdline.txt) cgroup_enable=cpuset cgroup_enable=memory"
echo $orig | sudo tee /boot/cmdline.txt
echo Please reboot
观光\评论区