forked from kubernetes-sigs/kubespray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add macvlan cni to kubespray (kubernetes-sigs#4901)
* add macvlan cni to kubespray * macvlan: lint yaml files and fix sample config file * macvlan: add OWNERS file * add macvlan to README * macvlan : CI first shoot * macvlan : CI add full masquerade * delegate retrive pod cidr to master only * macvlan: add config for CI * macvlan: add netchecker deployment
- Loading branch information
1 parent
bc7d1f3
commit f599c2a
Showing
29 changed files
with
438 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Macvlan | ||
=============== | ||
|
||
How to use it : | ||
------------- | ||
|
||
|
||
* Enable macvlan in `group_vars/k8s-cluster/k8s-cluster.yml` | ||
``` | ||
... | ||
kube_network_plugin: macvlan | ||
... | ||
``` | ||
|
||
|
||
* Adjust the `macvlan_interface` in `group_vars/k8s-cluster/k8s-net-macvlan.yml` or by host in the `host.yml` file: | ||
``` | ||
all: | ||
hosts: | ||
node1: | ||
ip: 10.2.2.1 | ||
access_ip: 10.2.2.1 | ||
ansible_host: 10.2.2.1 | ||
macvlan_interface: ens5 | ||
``` | ||
|
||
|
||
|
||
Issue encountered : | ||
------------- | ||
|
||
- Service DNS | ||
|
||
reply from unexpected source: | ||
|
||
add `kube_proxy_masquerade_all: true` in `group_vars/all/all.yml` | ||
|
||
|
||
- Disable nodelocaldns | ||
|
||
The nodelocal dns IP is not reacheable. | ||
|
||
Disable it in `sample/group_vars/k8s-cluster/k8s-cluster.yml` | ||
``` | ||
enable_nodelocaldns: false | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
# private interface, on a l2-network | ||
macvlan_interface: "eth1" | ||
|
||
# Enable nat in default gateway network interface | ||
enable_nat_default_gateway: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# See the OWNERS docs at https://go.k8s.io/owners | ||
|
||
approvers: | ||
- simon | ||
reviewers: | ||
- simon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
macvlan_interface: eth0 | ||
enable_nat_default_gateway: true | ||
|
||
# sysctl_file_path to add sysctl conf to | ||
sysctl_file_path: "/etc/sysctl.d/99-sysctl.conf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
POSTDOWNNAME="/etc/sysconfig/network-scripts/post-down-$1" | ||
if [ -x $POSTDOWNNAME ]; then | ||
exec $POSTDOWNNAME | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# | ||
# initscripts-macvlan | ||
# Copyright (C) 2014 Lars Kellogg-Stedman | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
. /etc/init.d/functions | ||
|
||
cd /etc/sysconfig/network-scripts | ||
. ./network-functions | ||
|
||
[ -f ../network ] && . ../network | ||
|
||
CONFIG=${1} | ||
|
||
need_config ${CONFIG} | ||
|
||
source_config | ||
|
||
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-${REAL_DEVICETYPE}" | ||
|
||
if [ ! -x ${OTHERSCRIPT} ]; then | ||
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-eth" | ||
fi | ||
|
||
${OTHERSCRIPT} ${CONFIG} | ||
|
||
ip link del ${DEVICE} type ${TYPE:-macvlan} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
POSTUPNAME="/etc/sysconfig/network-scripts/post-up-$1" | ||
if [ -x $POSTUPNAME ]; then | ||
exec $POSTUPNAME | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
# | ||
# initscripts-macvlan | ||
# Copyright (C) 2014 Lars Kellogg-Stedman | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
. /etc/init.d/functions | ||
|
||
cd /etc/sysconfig/network-scripts | ||
. ./network-functions | ||
|
||
[ -f ../network ] && . ../network | ||
|
||
CONFIG=${1} | ||
|
||
need_config ${CONFIG} | ||
|
||
source_config | ||
|
||
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${REAL_DEVICETYPE}" | ||
|
||
if [ ! -x ${OTHERSCRIPT} ]; then | ||
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth" | ||
fi | ||
|
||
ip link add \ | ||
link ${MACVLAN_PARENT} \ | ||
name ${DEVICE} \ | ||
type ${TYPE:-macvlan} mode ${MACVLAN_MODE:-private} | ||
|
||
${OTHERSCRIPT} ${CONFIG} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
- name: Macvlan | restart network | ||
command: /bin/true | ||
notify: | ||
- Macvlan | reload network | ||
when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] | ||
|
||
- name: Macvlan | reload network | ||
service: | ||
name: >- | ||
{% if ansible_os_family == "RedHat" -%} | ||
network | ||
{%- elif ansible_distribution == "Ubuntu" and ansible_distribution_release == "bionic" -%} | ||
systemd-networkd | ||
{%- elif ansible_os_family == "Debian" -%} | ||
networking | ||
{%- endif %} | ||
state: restarted | ||
when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and kube_network_plugin not in ['canal', 'calico'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
|
||
- name: Macvlan | Set cni directory permissions | ||
file: | ||
path: /opt/cni/bin | ||
state: directory | ||
owner: kube | ||
recurse: true | ||
mode: 0755 | ||
|
||
- name: Macvlan | Copy cni plugins | ||
unarchive: | ||
src: "{{ local_release_dir }}/cni-plugins-linux-{{ image_arch }}-{{ cni_version }}.tgz" | ||
dest: "/opt/cni/bin" | ||
mode: 0755 | ||
remote_src: yes | ||
|
||
- name: Macvlan | Retreive Pod Cidr | ||
command: "{{ bin_dir }}/kubectl get nodes {{ kube_override_hostname | default(inventory_hostname) }} -o jsonpath='{.spec.podCIDR}'" | ||
register: node_pod_cidr_cmd | ||
delegate_to: "{{ groups['kube-master'][0] }}" | ||
|
||
- name: Macvlan | set node_pod_cidr | ||
set_fact: | ||
node_pod_cidr={{ node_pod_cidr_cmd.stdout }} | ||
|
||
- name: Macvlan | Retreive default gateway network interface | ||
become: false | ||
raw: ip -4 route list 0/0 | sed 's/.*dev \([[:alnum:]]*\).*/\1/' | ||
register: node_default_gateway_interface_cmd | ||
|
||
- name: Macvlan | set node_default_gateway_interface | ||
set_fact: | ||
node_default_gateway_interface={{ node_default_gateway_interface_cmd.stdout | trim }} | ||
|
||
- name: Macvlan | Install network gateway interface on debian | ||
template: | ||
src: debian-network-macvlan.cfg.j2 | ||
dest: /etc/network/interfaces.d/60-mac0.cfg | ||
notify: Macvlan | restart network | ||
when: ansible_os_family in ["Debian"] | ||
|
||
- name: Macvlan | Install macvlan script on centos | ||
copy: | ||
src: "{{ item }}" | ||
dest: /etc/sysconfig/network-scripts/ | ||
owner: root | ||
group: root | ||
mode: "0755" | ||
with_fileglob: | ||
- files/* | ||
when: ansible_os_family in ["CentOS","RedHat"] | ||
|
||
- name: Macvlan | Install post-up script on centos | ||
copy: | ||
src: "files/ifup-local" | ||
dest: /sbin/ | ||
owner: root | ||
group: root | ||
mode: "0755" | ||
when: ansible_os_family in ["CentOS","RedHat"] and enable_nat_default_gateway | ||
|
||
- name: Macvlan | Install network gateway interface on centos | ||
template: | ||
src: "{{ item.src }}.j2" | ||
dest: "/etc/sysconfig/network-scripts/{{ item.dst }}" | ||
with_items: | ||
- {src: centos-network-macvlan.cfg, dst: ifcfg-mac0 } | ||
- {src: centos-routes-macvlan.cfg, dst: route-mac0 } | ||
- {src: centos-postup-macvlan.cfg, dst: post-up-mac0 } | ||
notify: Macvlan | restart network | ||
when: ansible_os_family in ["CentOS","RedHat"] | ||
|
||
- name: Macvlan | Install service nat via gateway on coreos | ||
template: | ||
src: coreos-service-nat_ouside.j2 | ||
dest: /etc/systemd/system/enable_nat_ouside.service | ||
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and enable_nat_default_gateway | ||
|
||
- name: Macvlan | Enable service nat via gateway on coreos | ||
command: "{{ item }}" | ||
with_items: | ||
- systemctl daemon-reload | ||
- systemctl enable enable_nat_ouside.service | ||
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and enable_nat_default_gateway | ||
|
||
- name: Macvlan | Install network gateway interface on coreos | ||
template: | ||
src: "{{ item.src }}.j2" | ||
dest: "/etc/systemd/network/{{ item.dst }}" | ||
with_items: | ||
- {src: coreos-device-macvlan.cfg, dst: macvlan.netdev } | ||
- {src: coreos-interface-macvlan.cfg, dst: output.network } | ||
- {src: coreos-network-macvlan.cfg, dst: macvlan.network } | ||
notify: Macvlan | restart network | ||
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] | ||
|
||
- name: Macvlan | Install cni definition for Macvlan | ||
template: | ||
src: 10-macvlan.conf.j2 | ||
dest: /etc/cni/net.d/10-macvlan.conf | ||
|
||
- name: Macvlan | Install loopback definition for Macvlan | ||
template: | ||
src: 99-loopback.conf.j2 | ||
dest: /etc/cni/net.d/99-loopback.conf | ||
|
||
- name: Enable net.ipv4.conf.all.arp_notify in sysctl | ||
sysctl: | ||
name: net.ipv4.conf.all.arp_notify | ||
value: 1 | ||
sysctl_set: yes | ||
sysctl_file: "{{ sysctl_file_path }}" | ||
state: present | ||
reload: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"cniVersion": "0.3.0", | ||
"name": "mynet", | ||
"type": "macvlan", | ||
"master": "{{ macvlan_interface }}", | ||
"hairpinMode": true, | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "{{ node_pod_cidr }}", | ||
"routes": [ | ||
{ "dst": "0.0.0.0/0" } | ||
], | ||
"gateway": "{{ node_pod_cidr|ipaddr('net')|ipaddr(1)|ipaddr('address') }}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cniVersion": "0.2.0", | ||
"name": "lo", | ||
"type": "loopback" | ||
} |
Oops, something went wrong.