mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2026-02-28 09:39:12 +03:00
split network plugins into distinct roles
This commit is contained in:
8
roles/network_plugin/flannel/defaults/main.yml
Normal file
8
roles/network_plugin/flannel/defaults/main.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# Flannel public IP
|
||||
# The address that flannel should advertise as how to access the system
|
||||
flannel_public_ip: "{{ access_ip|default(ip|default(ansible_default_ipv4.address)) }}"
|
||||
|
||||
## interface that should be used for flannel operations
|
||||
## This is actually an inventory node-level item
|
||||
# flannel_interface:
|
||||
26
roles/network_plugin/flannel/handlers/main.yml
Normal file
26
roles/network_plugin/flannel/handlers/main.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
- name: restart docker
|
||||
command: /bin/true
|
||||
notify:
|
||||
- reload systemd
|
||||
- reload docker
|
||||
- reload kubelet
|
||||
|
||||
- name: delete default docker bridge
|
||||
command: ip link delete docker0
|
||||
ignore_errors: yes
|
||||
notify: restart docker
|
||||
|
||||
- name : reload systemd
|
||||
shell: systemctl daemon-reload
|
||||
when: init_system == "systemd"
|
||||
|
||||
- name: reload docker
|
||||
service:
|
||||
name: docker
|
||||
state: restarted
|
||||
|
||||
- name: reload kubelet
|
||||
service:
|
||||
name: kubelet
|
||||
state: restarted
|
||||
52
roles/network_plugin/flannel/tasks/main.yml
Normal file
52
roles/network_plugin/flannel/tasks/main.yml
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
- name: Flannel | Write flannel configuration
|
||||
template:
|
||||
src: network.json
|
||||
dest: /etc/flannel-network.json
|
||||
backup: yes
|
||||
|
||||
- name: Flannel | Create flannel pod manifest
|
||||
template:
|
||||
src: flannel-pod.yml
|
||||
dest: /etc/kubernetes/manifests/flannel-pod.manifest
|
||||
notify: delete default docker bridge
|
||||
|
||||
- name: Flannel | Wait for flannel subnet.env file presence
|
||||
wait_for:
|
||||
path: /run/flannel/subnet.env
|
||||
delay: 5
|
||||
|
||||
- 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
|
||||
|
||||
- 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
|
||||
|
||||
- set_fact:
|
||||
flannel_mtu: "{{ flannel_mtu_output.stdout }}"
|
||||
|
||||
- name: Flannel | Set docker daemon options
|
||||
template:
|
||||
src: docker
|
||||
dest: "/etc/default/docker"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify:
|
||||
- restart docker
|
||||
|
||||
- name: Flannel | Write docker.service systemd file
|
||||
template:
|
||||
src: systemd-docker.service
|
||||
dest: /lib/systemd/system/docker.service
|
||||
notify: restart docker
|
||||
when: init_system == "systemd"
|
||||
|
||||
- meta: flush_handlers
|
||||
6
roles/network_plugin/flannel/templates/docker
Normal file
6
roles/network_plugin/flannel/templates/docker
Normal file
@@ -0,0 +1,6 @@
|
||||
# Deployed by Ansible
|
||||
{% if init_system == "sysvinit" and kube_network_plugin == "flannel" and ansible_os_family == "Debian" %}
|
||||
DOCKER_OPTS="--bip={{ flannel_subnet }} --mtu={{ flannel_mtu }}"
|
||||
{% elif kube_network_plugin == "flannel" %}
|
||||
OPTIONS="--bip={{ flannel_subnet }} --mtu={{ flannel_mtu }}"
|
||||
{% endif %}
|
||||
46
roles/network_plugin/flannel/templates/flannel-pod.yml
Normal file
46
roles/network_plugin/flannel/templates/flannel-pod.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
kind: "Pod"
|
||||
apiVersion: "v1"
|
||||
metadata:
|
||||
name: "flannel"
|
||||
namespace: "kube-system"
|
||||
labels:
|
||||
app: "flannel"
|
||||
version: "v0.1"
|
||||
spec:
|
||||
volumes:
|
||||
- name: "subnetenv"
|
||||
hostPath:
|
||||
path: "/run/flannel"
|
||||
- name: "networkconfig"
|
||||
hostPath:
|
||||
path: "/etc/flannel-network.json"
|
||||
containers:
|
||||
- name: "flannel-server-helper"
|
||||
image: "gcr.io/google_containers/flannel-server-helper:0.1"
|
||||
args:
|
||||
- "--network-config=/etc/flannel-network.json"
|
||||
- "--etcd-prefix=/{{ cluster_name }}/network"
|
||||
- "--etcd-server=http://{{ groups['etcd'][0] }}:2379"
|
||||
volumeMounts:
|
||||
- name: "networkconfig"
|
||||
mountPath: "/etc/flannel-network.json"
|
||||
imagePullPolicy: "Always"
|
||||
- name: "flannel-container"
|
||||
image: "quay.io/coreos/flannel:0.5.5"
|
||||
command:
|
||||
- "/bin/sh"
|
||||
- "-c"
|
||||
- "/opt/bin/flanneld -etcd-endpoints {% for srv in groups['etcd'] %}http://{{ srv }}:2379{% if not loop.last %},{% endif %}{% endfor %} -etcd-prefix /{{ cluster_name }}/network {% if flannel_interface is defined %}-iface {{ flannel_interface }}{% endif %} {% if flannel_public_ip is defined %}-public-ip {{ flannel_public_ip }}{% endif %} 1>>/var/log/flannel_server.log 2>&1"
|
||||
ports:
|
||||
- hostPort: 10253
|
||||
containerPort: 10253
|
||||
resources:
|
||||
limits:
|
||||
cpu: "100m"
|
||||
volumeMounts:
|
||||
- name: "subnetenv"
|
||||
mountPath: "/run/flannel"
|
||||
securityContext:
|
||||
privileged: true
|
||||
hostNetwork: true
|
||||
1
roles/network_plugin/flannel/templates/network.json
Normal file
1
roles/network_plugin/flannel/templates/network.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "Network": "{{ kube_pods_subnet }}", "SubnetLen": {{ kube_network_node_prefix }}, "Backend": { "Type": "vxlan" } }
|
||||
@@ -0,0 +1,28 @@
|
||||
[Unit]
|
||||
Description=Docker Application Container Engine
|
||||
Documentation=http://docs.docker.com
|
||||
{% if ansible_os_family == "RedHat" %}
|
||||
After=network.target
|
||||
Wants=docker-storage-setup.service
|
||||
{% elif ansible_os_family == "Debian" %}
|
||||
After=network.target docker.socket
|
||||
Requires=docker.socket
|
||||
{% endif %}
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
EnvironmentFile=-/etc/default/docker
|
||||
Environment=GOTRACEBACK=crash
|
||||
ExecStart=/usr/bin/docker daemon \
|
||||
$OPTIONS \
|
||||
$DOCKER_STORAGE_OPTIONS \
|
||||
$DOCKER_NETWORK_OPTIONS \
|
||||
$INSECURE_REGISTRY
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=1048576
|
||||
LimitCORE=infinity
|
||||
MountFlags=slave
|
||||
TimeoutStartSec=1min
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user