[关闭]
@mritd 2017-10-10T08:00:14.000000Z 字数 3169 阅读 1767

Kubernetes 1.8 kube-proxy 开启 ipvs

Kubernetes


Kubernetes 1.8 发布已经好几天,1.8 对于 kube-proxy 组件增加了 ipvs 支持,以下记录一下 kube-proxy ipvs 开启教程

一、环境准备

目前测试为 5 台虚拟机,CentOS 系统,etcd、kubernetes 全部采用 rpm 安装,使用 systemd 来做管理,网络组件采用 calico,Master 实现了 HA;基本环境如下

IP 组件
10.10.1.5 Master、Node、etcd
10.10.1.6 Master、Node、etcd
10.10.1.7 Master、Node、etcd
10.10.1.8 Node
10.10.1.9 Node

二、注意事项

之所以把这个单独写一个标题是因为坑有点多,为了避免下面出现问题,先说一下注意事项:

2.1、SELinux

如果对 SELinux 玩的不溜的朋友,我建议先关闭 SELinux,关闭方法如下

  1. # 编辑 /etc/selinux/config 文件;确保 SELINUX=disabled
  2. docker1.node ~ cat /etc/selinux/config
  3. # This file controls the state of SELinux on the system.
  4. # SELINUX= can take one of these three values:
  5. # enforcing - SELinux security policy is enforced.
  6. # permissive - SELinux prints warnings instead of enforcing.
  7. # disabled - No SELinux policy is loaded.
  8. SELINUX=disabled
  9. # SELINUXTYPE= can take one of three two values:
  10. # targeted - Targeted processes are protected,
  11. # minimum - Modification of targeted policy. Only selected processes are protected.
  12. # mls - Multi Level Security protection.
  13. SELINUXTYPE=targeted

然后重启机器并验证

  1. docker1.node ~ sestatus
  2. SELinux status: disabled

2.2、Firewall

搭建时尽量关闭防火墙,如果你玩的很溜,那么请在测试没问题后再开启防火墙

  1. systemctl stop firewalld
  2. systemctl disable firewalld

2.3、内核参数调整

确保内核已经开启如下参数,或者说确保 /etc/sysctl.conf 有如下配置

  1. docker1.node ~ cat /etc/sysctl.conf
  2. # sysctl settings are defined through files in
  3. # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
  4. #
  5. # Vendors settings live in /usr/lib/sysctl.d/.
  6. # To override a whole file, create a new file with the same in
  7. # /etc/sysctl.d/ and put new settings there. To override
  8. # only specific settings, add a file with a lexically later
  9. # name in /etc/sysctl.d/ and put new settings there.
  10. #
  11. # For more information, see sysctl.conf(5) and sysctl.d(5).
  12. net.ipv4.ip_forward=1
  13. net.bridge.bridge-nf-call-iptables=1
  14. net.bridge.bridge-nf-call-ip6tables=1

然后执行 sysctl -p 使之生效

  1. docker1.node ~ sysctl -p
  2. net.ipv4.ip_forward = 1
  3. net.bridge.bridge-nf-call-iptables = 1
  4. net.bridge.bridge-nf-call-ip6tables = 1

2.4、内核模块加载

由于 ipvs 已经加入到内核主干,所以需要内核模块支持,请确保内核已经加载了相应模块;如不确定,执行以下脚本,以确保内核加载相应模块,否则会出现 failed to load kernel modules: [ip_vs_rr ip_vs_sh ip_vs_wrr] 错误

  1. cat > /etc/sysconfig/modules/ipvs.modules <<EOF
  2. #!/bin/bash
  3. ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack_ipv4"
  4. for kernel_module in \${ipvs_modules}; do
  5. /sbin/modinfo -F filename \${kernel_module} > /dev/null 2>&1
  6. if [ $? -eq 0 ]; then
  7. /sbin/modprobe \${kernel_module}
  8. fi
  9. done
  10. EOF
  11. chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs

执行后应该如下图所示,如果 lsmod | grep ip_vs 并未出现 ip_vs_rr 等模块那么请更换内核(一般不会,2.6 以后 ipvs 好像已经就合并进主干了)

Load kernel modules

三、开启 ipvs 支持

3.1、修改配置

修改 /etc/kubernetes/proxy 配置如下

  1. ###
  2. # kubernetes proxy config
  3. # default config should be adequate
  4. # Add your own!
  5. KUBE_PROXY_ARGS="--bind-address=10.10.1.8 \
  6. --hostname-override=docker4.node \
  7. --feature-gates=SupportIPVSProxyMode=true \
  8. --proxy-mode=ipvs \
  9. --ipvs-min-sync-period=5s \
  10. --ipvs-sync-period=5s \
  11. --ipvs-scheduler=rr \
  12. --kubeconfig=/etc/kubernetes/kube-proxy.kubeconfig \
  13. --cluster-cidr=10.254.0.0/16"

启用 ipvs 后与 1.7 版本的配置差异如下:

3.2、测试 ipvs

修改完成后,重启 kube-proxy 使其生效

  1. systemctl daemon-reload
  2. systemctl restart kube-proxy

重启后日志中应该能看到如下输出,不应该有其他提示 ipvs 的错误信息出现

kube-proxy ipvs log

同时使用 ipvsadm 命令应该能看到相应的 service 的 ipvs 规则(ipvsadm 自己安装一下)

ipvs role

然后进入 Pod 测试

test ipvs1

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注