Dynadot Jtti 搬瓦工 腾讯云

树莓派 Raspberry Pi 3 Model B+ 上部署安装 Docker 和 Kubernetes

GigsGigsCloud

今天在树莓派上部署了一下 Docker 和 Kubernetes,有一些坑,记录一下。本文基于树莓派 Raspberry Pi 3 Model B+ 的原生系统(原生系统是基于 Debian 的,使用起来也比较方便),通过本文可以成功的在树莓派上安装 Docker,安装 Kubernetes,并运行。

一、安装 Docker CE

树莓派上目前自带的通过 apt install 安装的 docker.io 的版本是 18.XX,版本太高,后续安装 Kubernetes 的时候会提示不支持该版本,所以我们需要通过添加源,然后指定 Docker 的版本进行安装。目前测试下来 17.09.1~ce-0~debian 这个版本在树莓派上可以安装,其他版本可能会提示版本不兼容。

1、安装必要组件

sudo apt-get update
sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common

2、添加 GPG key

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

3、添加源

echo "deb [arch=armhf] https://download.docker.com/linux/debian \
     $(lsb_release -cs) stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list

4、安装 Docker

sudo apt-get update
sudo apt-get install docker-ce=18.06.2~ce-0~debian

5、查看 Docker 版本信息

docker --version

至此,Docker CE 17.09.1 安装成功。

二、安装 Kubernetes

下面开始安装 Kubernetes,会遇到一些问题,会依次解决,不要慌。

1、添加源

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list

2、安装 kubeadm

apt-get update && apt-get install -y kubeadm

3、尝试运行 kubernetes

kubeadm init --pod-network-cidr 10.244.0.0/16

会提示如下问题:

CGROUPS_MEMORY: missing
[WARNING SystemVerification]: missing cgroups: memory
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[ERROR Swap]: running with swap on is not supported. Please disable swap
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

依次解决问题。

首先是 [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist,这个解决很简单,输入下面语句回车即可:

modprobe br_netfilter

其次是 [ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1,这个也比较简单,输入下列语句回车:

echo 1 > /proc/sys/net/ipv4/ip_forward

然后是 [ERROR Swap]: running with swap on is not supported. Please disable swap,这个只需要关闭 swap 即可:

swapoff -a

解决上面问题后,重新运行 kubeadm init,还是会提示问题,会提示:[ERROR SystemVerification]: missing cgroups: memory,这个也能解决,编辑 /boot/cmdline.txt 这个文件,加入下面两句:

cgroup_enable=memory  cgroup_memory=1

然后 reboot 重启一下即可。

注意:重启后第一、第二、第三个问题可能会再次出现,再次操作一下即可。最后,再次尝试 kubeadm init,就会出现久违的成功界面:

三、参考文献

Dynadot Hostwinds
赞(1)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《树莓派 Raspberry Pi 3 Model B+ 上部署安装 Docker 和 Kubernetes
文章链接:https://oldtang.com/1975.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。