本地用vagrant和ansible搭建k8s集群踩的坑

2019-11-10  本文已影响0人  无知者云

源代码请访问:https://github.com/davenkin/local-k8s-cluster

- name: add Kubernetes apt-key
  apt_key:
    url: https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg
    state: present

- name: Add Kubernetes' APT repository
  apt_repository:
    repo: deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
    state: present
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.28.128.228
sudo vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

添加:

Environment="KUBELET_EXTRA_ARGS=--node-ip=[ip from above, e.g. 172.28.128.228]"

到:

[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
Environment="KUBELET_EXTRA_ARGS=--node-ip=[ip from above, e.g. 172.28.128.228]"

然后重启kubelet:

sudo systemctl daemon-reload
sudo systemctl restart kubelet

更多相关信息,参考这里

sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.28.128.228

在master节点上,先删除掉之前的Flannel:

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

然后下载Flannel配置文件:

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

添加iface=enp0s8kube-flannel.yml文件中,如下:

  containers:
  - name: kube-flannel
    image: quay.io/coreos/flannel:v0.10.0-amd64
    command:
    - /opt/bin/flanneld
    args:
    - --ip-masq
    - --kube-subnet-mgr
    - --iface=enp0s8

这里的enp0s8为你要使用的IP地址所对应的网卡名称,通过ifconfig -a可以查看。

另外,安装cluster之前需要做的:

setenforce 0
swapoff -a

或者直接编辑/etc/fstab文件,永久删除swap行。

systemctl disable firewalld
systemctl stop firewalld

对于ubuntu:

sudo ufw disable
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
上一篇 下一篇

猜你喜欢

热点阅读