mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2026-02-28 09:39:12 +03:00
Calico is not a network overlay
This commit is contained in:
28
roles/network_plugin/handlers/main.yml
Normal file
28
roles/network_plugin/handlers/main.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- name: restart calico-node
|
||||
service: name=calico-node state=restarted
|
||||
|
||||
- name: restart docker
|
||||
service: name=docker state=restarted
|
||||
|
||||
- name: restart flannel
|
||||
service: name=flannel state=restarted
|
||||
notify:
|
||||
- reload systemd
|
||||
- stop docker
|
||||
- delete docker0
|
||||
- start docker
|
||||
when: inventory_hostname in groups['kube-node']
|
||||
|
||||
- name: stop docker
|
||||
service: name=docker state=stopped
|
||||
|
||||
- name: delete docker0
|
||||
command: ip link delete docker0
|
||||
ignore_errors: yes
|
||||
|
||||
- name: start docker
|
||||
service: name=docker state=started
|
||||
|
||||
- name : reload systemd
|
||||
shell: systemctl daemon-reload
|
||||
46
roles/network_plugin/tasks/calico.yml
Normal file
46
roles/network_plugin/tasks/calico.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: Calico | Install calicoctl bin
|
||||
copy:
|
||||
src={{ local_release_dir }}/calico/bin/calicoctl
|
||||
dest={{ bin_dir }}
|
||||
mode=u+x
|
||||
notify: restart calico-node
|
||||
|
||||
- name: Calico | Create calicoctl symlink (needed by kubelet)
|
||||
file: src=/usr/local/bin/calicoctl dest=/usr/bin/calicoctl state=link
|
||||
|
||||
- name: Calico | Write calico-node systemd init file
|
||||
template: src=calico/calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
|
||||
notify:
|
||||
- reload systemd
|
||||
- restart calico-node
|
||||
|
||||
- name: Calico | Write network-environment
|
||||
template: src=calico/network-environment.j2 dest=/etc/network-environment mode=u+x
|
||||
notify:
|
||||
- reload systemd
|
||||
- restart calico-node
|
||||
|
||||
- name: Calico | Enable calico-node
|
||||
service: name=calico-node enabled=yes state=started
|
||||
|
||||
- name: Calico | Configure calico-node remove default pool
|
||||
shell: calicoctl pool remove 192.168.0.0/16
|
||||
environment:
|
||||
ETCD_AUTHORITY: "{{ groups['kube-master'][0] }}:4001"
|
||||
run_once: true
|
||||
|
||||
- name: Calico | Configure calico-node desired pool
|
||||
shell: calicoctl pool add {{ kube_pods_subnet }}
|
||||
environment:
|
||||
ETCD_AUTHORITY: "{{ groups['kube-master'][0] }}:4001"
|
||||
run_once: true
|
||||
|
||||
- name: Calico | Disable node mesh
|
||||
shell: calicoctl bgp node-mesh off
|
||||
when: peer_with_router and inventory_hostname in groups['kube-node']
|
||||
|
||||
- name: Calico | Configure peering with router(s)
|
||||
shell: calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}
|
||||
with_items: peers
|
||||
when: peer_with_router and inventory_hostname in groups['kube-node']
|
||||
57
roles/network_plugin/tasks/flannel.yml
Normal file
57
roles/network_plugin/tasks/flannel.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
- name: Create flannel user
|
||||
user: name=flannel shell=/bin/nologin
|
||||
|
||||
- name: Install flannel binaries
|
||||
copy:
|
||||
src={{ local_release_dir }}/flannel/bin/flanneld
|
||||
dest={{ bin_dir }}
|
||||
owner=flannel
|
||||
mode=u+x
|
||||
notify:
|
||||
- restart flannel
|
||||
|
||||
- name: Write flannel.service systemd file
|
||||
template:
|
||||
src: flannel/systemd-flannel.service.j2
|
||||
dest: /etc/systemd/system/flannel.service
|
||||
notify: restart flannel
|
||||
|
||||
- name: Write docker.service systemd file
|
||||
template:
|
||||
src: flannel/systemd-docker.service.j2
|
||||
dest: /lib/systemd/system/docker.service
|
||||
notify: restart docker
|
||||
|
||||
- name: Set fact for ectcd command conf file location
|
||||
set_fact:
|
||||
conf_file: "/tmp/flannel-conf.json"
|
||||
run_once: true
|
||||
delegate_to: "{{ groups['kube-master'][0] }}"
|
||||
|
||||
- name: Create flannel config file to go in etcd
|
||||
template: src=flannel/flannel-conf.json.j2 dest={{ conf_file }}
|
||||
run_once: true
|
||||
delegate_to: "{{ groups['kube-master'][0] }}"
|
||||
|
||||
- name: Flannel configuration into etcd
|
||||
shell: "{{ bin_dir }}/etcdctl set /{{ cluster_name }}/network/config < {{ conf_file }}"
|
||||
delegate_to: "{{ groups['kube-master'][0] }}"
|
||||
notify: restart flannel
|
||||
|
||||
- name: Clean up the flannel config file
|
||||
file: path=/tmp/flannel-config.json state=absent
|
||||
run_once: true
|
||||
delegate_to: "{{ groups['kube-master'][0] }}"
|
||||
|
||||
- name: Write network-environment
|
||||
template: src=flannel/network-environment.j2 dest=/etc/network-environment mode=u+x
|
||||
notify: restart flannel
|
||||
|
||||
- name: Launch Flannel
|
||||
service: name=flannel state=started enabled=yes
|
||||
notify:
|
||||
- restart flannel
|
||||
|
||||
- name: Enable Docker
|
||||
service: name=docker enabled=yes state=started
|
||||
13
roles/network_plugin/tasks/main.yml
Normal file
13
roles/network_plugin/tasks/main.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: "Test if network plugin is defined"
|
||||
fail: msg="ERROR, One network_plugin variable must be defined (Flannel or Calico)"
|
||||
when: ( kube_network_plugin is defined and kube_network_plugin == "calico" and kube_network_plugin == "flannel" ) or
|
||||
kube_network_plugin is not defined
|
||||
|
||||
- include: flannel.yml
|
||||
when: kube_network_plugin == "flannel"
|
||||
- include: calico.yml
|
||||
when: kube_network_plugin == "calico"
|
||||
|
||||
- meta: flush_handlers
|
||||
|
||||
23
roles/network_plugin/templates/calico/calico-node.service.j2
Normal file
23
roles/network_plugin/templates/calico/calico-node.service.j2
Normal file
@@ -0,0 +1,23 @@
|
||||
[Unit]
|
||||
Description=calicoctl node
|
||||
After=etcd2.service
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/network-environment
|
||||
User=root
|
||||
PermissionsStartOnly=true
|
||||
ExecStartPre={{ bin_dir }}/calicoctl checksystem --fix
|
||||
{% if inventory_hostname in groups['kube-node'] %}
|
||||
{% if peer_with_router %}
|
||||
ExecStart={{ bin_dir }}/calicoctl node --ip=${DEFAULT_IPV4} --as={{ local_as }} --kubernetes
|
||||
{% else %}
|
||||
ExecStart={{ bin_dir }}/calicoctl node --ip=${DEFAULT_IPV4} --kubernetes
|
||||
{% endif %}
|
||||
{% else %}
|
||||
ExecStart={{ bin_dir }}/calicoctl node --ip=${DEFAULT_IPV4}
|
||||
{% endif %}
|
||||
RemainAfterExit=yes
|
||||
Type=oneshot
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
19
roles/network_plugin/templates/calico/network-environment.j2
Executable file
19
roles/network_plugin/templates/calico/network-environment.j2
Executable file
@@ -0,0 +1,19 @@
|
||||
#! /usr/bin/bash
|
||||
# This node's IPv4 address
|
||||
CALICO_IPAM=true
|
||||
DEFAULT_IPV4={{ ansible_default_ipv4.address }}
|
||||
|
||||
{% if inventory_hostname in groups['kube-node'] %}
|
||||
# The kubernetes master IP
|
||||
KUBERNETES_MASTER={{ groups['kube-master'][0] }}
|
||||
|
||||
# Location of etcd cluster used by Calico. By default, this uses the etcd
|
||||
# instance running on the Kubernetes Master
|
||||
ETCD_AUTHORITY={{ groups['kube-master'][0] }}:4001
|
||||
|
||||
# The kubernetes-apiserver location - used by the calico plugin
|
||||
KUBE_API_ROOT=http://{{ groups['kube-master'][0] }}:8080/api/v1/
|
||||
|
||||
# Location of the calicoctl binary - used by the calico plugin
|
||||
CALICOCTL_PATH="{{ bin_dir }}/calicoctl"
|
||||
{% endif %}
|
||||
@@ -0,0 +1 @@
|
||||
{ "Network": "{{ kube_service_addresses }}", "SubnetLen": {{ kube_network_node_prefix }}, "Backend": { "Type": "vxlan" } }
|
||||
@@ -0,0 +1 @@
|
||||
FLANNEL_ETCD_PREFIX="--etcd-prefix=/{{ cluster_name }}/network"
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Docker Application Container Engine
|
||||
Documentation=http://docs.docker.com
|
||||
After=network.target docker.socket flannel.service
|
||||
Requires=docker.socket
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/run/flannel/subnet.env
|
||||
EnvironmentFile=-/etc/default/docker
|
||||
ExecStart=/usr/bin/docker -d -H fd:// --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} $DOCKER_OPTS
|
||||
MountFlags=slave
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=1048576
|
||||
LimitCORE=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Flannel Network Overlay
|
||||
Documentation=https://coreos.com/flannel/docs/latest
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/network-environment
|
||||
ExecStart={{ bin_dir }}/flanneld \
|
||||
$FLANNEL_ETCD_PREFIX
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user