无法在Vagrant上安装Kubernetes

时间:2017-05-23 02:54:54

标签: docker vagrant virtualbox kubernetes

使用本指南在Vagrant群集上安装Kubernetes:

https://kubernetes.io/docs/getting-started-guides/kubeadm/

(2/4) Initializing your master,出现了一些错误:

[root@localhost ~]# kubeadm init
[kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters.
[init] Using Kubernetes version: v1.6.4
[init] Using Authorization mode: RBAC
[preflight] Running pre-flight checks
[preflight] Some fatal errors occurred:
    /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can skip pre-flight checks with `--skip-preflight-checks`

我查看了/proc/sys/net/bridge/bridge-nf-call-iptables文件内容,其中只有一个0

(3/4) Installing a pod network,我下载了kube-flannel个文件:

https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

并运行kubectl apply -f kube-flannel.yml,收到错误:

[root@localhost ~]# kubectl apply -f kube-flannel.yml
The connection to the server localhost:8080 was refused - did you specify the right host or port?

直到这里,我不知道该怎么做。

我的Vagrantfile

  # Master Server
  config.vm.define "master", primary: true do |master|
    master.vm.network :private_network, ip: "192.168.33.200"
    master.vm.network :forwarded_port, guest: 22, host: 1234, id: 'ssh'
  end

4 个答案:

答案 0 :(得分:12)

要通过编辑/proc/sys/net/bridge/bridge-nf-call-iptables来设置/etc/sysctl.conf。在那里你可以添加[1]

net.bridge.bridge-nf-call-iptables = 1

然后执行

sudo sysctl -p

将会应用更改。有了这个,飞行前检查应该通过。

[1] http://wiki.libvirt.org/page/Net.bridge.bridge-nf-call_and_sysctl.conf

答案 1 :(得分:7)

是的,上面的答案是正确的,但我面对

  

不能stat / proc / sys / net / bridge / bridge-nf-call-ip6tables:没有这样的文件或目录

所以我做了

modprobe br_netfilter

echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
sudo sysctl -p

然后解决了。

答案 2 :(得分:0)

在Ubuntu 16.04上,我只需要:

modprobe br_netfilter

/proc/sys/net/bridge/bridge-nf-call-iptables中的默认值已为1

然后我将br_netfilter添加到/etc/modules以在下次启动时自动加载模块。

答案 3 :(得分:0)

如K8s文档中所述-Installing kubeadm让iptables查看桥接流量部分:

确保已加载br_netfilter模块。可以做到 通过运行lsmod | grep br_netfilter
要显式加载,请调用 sudo modprobe br_netfilter

作为Linux节点iptables正确查看的要求 桥接流量,您应确保 在您的系统中net.bridge.bridge-nf-call-iptables设置为1 配置,例如

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

关于预检错误-您可以在Kubeadm Implementation details预检检查下看到:

Kubeadm在启动init之前执行一组预检检查, 旨在验证前提条件并避免常见的集群启动 问题。

以下缺少的配置将产生错误:

.
.
if /proc/sys/net/bridge/bridge-nf-call-iptables file does not exist/does not contain 1

if advertise address is ipv6 and /proc/sys/net/bridge/bridge-nf-call-ip6tables does not exist/does not contain 1.

if swap is on
.
.