mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2026-02-24 22:46:06 -03:30
Initial version of Flannel using CNI (#1486)
* Updates Controller Manager/Kubelet with Flannel's required configuration for CNI * Removes old Flannel installation * Install CNI enabled Flannel DaemonSet/ConfigMap/CNI bins and config (with portmap plugin) on host * Uses RBAC if enabled * Fixed an issue that could occur if br_netfilter is not a module and net.bridge.bridge-nf-call-iptables sysctl was not set
This commit is contained in:
committed by
Matthew Mosesohn
parent
4550dccb84
commit
a39e78d42d
@@ -1,83 +1,47 @@
|
||||
---
|
||||
- name: Flannel | Set Flannel etcd configuration
|
||||
command: |-
|
||||
{{ bin_dir }}/etcdctl --peers={{ etcd_access_addresses }} \
|
||||
set /{{ cluster_name }}/network/config \
|
||||
'{ "Network": "{{ kube_pods_subnet }}", "SubnetLen": {{ kube_network_node_prefix }}, "Backend": { "Type": "{{ flannel_backend_type }}" } }'
|
||||
delegate_to: "{{groups['etcd'][0]}}"
|
||||
run_once: true
|
||||
- include: pre-upgrade.yml
|
||||
|
||||
- name: Flannel | Create flannel certs directory
|
||||
file:
|
||||
dest: "{{ flannel_cert_dir }}"
|
||||
state: directory
|
||||
mode: 0750
|
||||
owner: root
|
||||
group: root
|
||||
- name: Flannel | Verify if br_netfilter module exists
|
||||
shell: "modinfo br_netfilter"
|
||||
register: modinfo_br_netfilter
|
||||
failed_when: modinfo_br_netfilter.rc not in [0, 1]
|
||||
changed_when: false
|
||||
|
||||
- name: Flannel | Link etcd certificates for flanneld
|
||||
file:
|
||||
src: "{{ etcd_cert_dir }}/{{ item.s }}"
|
||||
dest: "{{ flannel_cert_dir }}/{{ item.d }}"
|
||||
state: hard
|
||||
force: yes
|
||||
- name: Flannel | Enable br_netfilter module
|
||||
modprobe:
|
||||
name: br_netfilter
|
||||
state: present
|
||||
when: modinfo_br_netfilter.rc == 0
|
||||
|
||||
# kube-proxy needs net.bridge.bridge-nf-call-iptables enabled when found if br_netfilter is not a module
|
||||
- name: Flannel | Check if bridge-nf-call-iptables key exists
|
||||
command: "sysctl net.bridge.bridge-nf-call-iptables"
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
register: sysctl_bridge_nf_call_iptables
|
||||
|
||||
- name: Flannel | Enable bridge-nf-call tables
|
||||
sysctl:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
value: 1
|
||||
reload: yes
|
||||
when: modinfo_br_netfilter.rc == 1 and sysctl_bridge_nf_call_iptables.rc == 0
|
||||
with_items:
|
||||
- {s: "ca.pem", d: "ca_cert.crt"}
|
||||
- {s: "node-{{ inventory_hostname }}.pem", d: "cert.crt"}
|
||||
- {s: "node-{{ inventory_hostname }}-key.pem", d: "key.pem"}
|
||||
- net.bridge.bridge-nf-call-iptables
|
||||
- net.bridge.bridge-nf-call-arptables
|
||||
- net.bridge.bridge-nf-call-ip6tables
|
||||
|
||||
- name: Flannel | Create flannel pod manifest
|
||||
- name: Flannel | Create cni-flannel-rbac manifest
|
||||
template:
|
||||
src: flannel-pod.yml
|
||||
dest: "{{kube_manifest_dir}}/flannel-pod.manifest"
|
||||
notify: Flannel | delete default docker bridge
|
||||
src: cni-flannel-rbac.yml.j2
|
||||
dest: "{{ kube_config_dir }}/cni-flannel-rbac.yml"
|
||||
register: flannel_rbac_manifest
|
||||
when: inventory_hostname == groups['kube-master'][0] and rbac_enabled
|
||||
|
||||
- name: Flannel | Wait for flannel subnet.env file presence
|
||||
wait_for:
|
||||
path: /run/flannel/subnet.env
|
||||
delay: 5
|
||||
timeout: 600
|
||||
|
||||
- name: Flannel | Get flannel_subnet from subnet.env
|
||||
shell: cat /run/flannel/subnet.env | awk -F'=' '$1 == "FLANNEL_SUBNET" {print $2}'
|
||||
register: flannel_subnet_output
|
||||
changed_when: false
|
||||
check_mode: no
|
||||
|
||||
- set_fact:
|
||||
flannel_subnet: "{{ flannel_subnet_output.stdout }}"
|
||||
|
||||
- name: Flannel | Get flannel_mtu from subnet.env
|
||||
shell: cat /run/flannel/subnet.env | awk -F'=' '$1 == "FLANNEL_MTU" {print $2}'
|
||||
register: flannel_mtu_output
|
||||
changed_when: false
|
||||
check_mode: no
|
||||
|
||||
- set_fact:
|
||||
flannel_mtu: "{{ flannel_mtu_output.stdout }}"
|
||||
|
||||
- set_fact:
|
||||
docker_options_file: >-
|
||||
{%- if ansible_os_family == "Debian" -%}/etc/default/docker{%- elif ansible_os_family == "RedHat" -%}/etc/sysconfig/docker{%- endif -%}
|
||||
tags: facts
|
||||
|
||||
- set_fact:
|
||||
docker_options_name: >-
|
||||
{%- if ansible_os_family == "Debian" -%}DOCKER_OPTS{%- elif ansible_os_family == "RedHat" -%}other_args{%- endif -%}
|
||||
tags: facts
|
||||
|
||||
- set_fact:
|
||||
docker_network_options: '"--bip={{ flannel_subnet }} --mtu={{ flannel_mtu }}"'
|
||||
|
||||
- name: Flannel | Ensure path for docker network systemd drop-in
|
||||
file:
|
||||
path: "/etc/systemd/system/docker.service.d"
|
||||
state: directory
|
||||
owner: root
|
||||
|
||||
- name: Flannel | Create docker network systemd drop-in
|
||||
- name: Flannel | Create cni-flannel manifest
|
||||
template:
|
||||
src: flannel-options.conf.j2
|
||||
dest: "/etc/systemd/system/docker.service.d/flannel-options.conf"
|
||||
notify:
|
||||
- Flannel | restart docker
|
||||
src: cni-flannel.yml.j2
|
||||
dest: "{{ kube_config_dir }}/cni-flannel.yml"
|
||||
register: flannel_manifest
|
||||
when: inventory_hostname == groups['kube-master'][0]
|
||||
19
roles/network_plugin/flannel/tasks/pre-upgrade.yml
Normal file
19
roles/network_plugin/flannel/tasks/pre-upgrade.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Flannel pre-upgrade | Purge legacy flannel systemd unit file
|
||||
file:
|
||||
path: "/etc/systemd/system/docker.service.d/flannel-options.conf"
|
||||
state: absent
|
||||
notify:
|
||||
- Flannel | delete default docker bridge
|
||||
|
||||
- name: Flannel pre-upgrade | Purge legacy Flannel static pod manifest
|
||||
file:
|
||||
path: "{{ kube_manifest_dir }}/flannel-pod.manifest"
|
||||
state: absent
|
||||
notify:
|
||||
- Flannel | delete flannel interface
|
||||
|
||||
- name: Flannel pre-upgrade | Remove Flannel's certificate directory not required by CNI
|
||||
file:
|
||||
dest: "{{ flannel_cert_dir }}"
|
||||
state: absent
|
||||
Reference in New Issue
Block a user