2016-11-28 20:18:06 +08:00
|
|
|
---
|
|
|
|
- hosts: kube-node
|
|
|
|
tasks:
|
|
|
|
- name: Test tunl0 routes
|
|
|
|
shell: "! /sbin/ip ro | grep '/26 via' | grep -v tunl0"
|
2018-10-11 15:45:00 +08:00
|
|
|
when:
|
2020-04-29 21:34:24 +08:00
|
|
|
- (ipip|default(true) or cloud_provider is defined)
|
|
|
|
- kube_network_plugin|default('calico') == 'calico'
|
2016-11-28 20:18:06 +08:00
|
|
|
|
|
|
|
- hosts: k8s-cluster
|
|
|
|
vars:
|
|
|
|
agent_report_interval: 10
|
|
|
|
netcheck_namespace: default
|
|
|
|
netchecker_port: 31081
|
|
|
|
|
|
|
|
tasks:
|
2020-04-15 14:48:02 +08:00
|
|
|
- name: Flannel | Disable tx and rx offloading on VXLAN interfaces (see https://github.com/coreos/flannel/pull/1282)
|
|
|
|
shell: "ethtool --offload flannel.1 rx off tx off"
|
|
|
|
ignore_errors: true
|
|
|
|
when:
|
2020-04-29 21:34:24 +08:00
|
|
|
- kube_network_plugin|default('calico') == 'flannel'
|
2020-04-15 14:48:02 +08:00
|
|
|
|
2020-02-18 16:15:29 +08:00
|
|
|
- name: Force binaries directory for Container Linux by CoreOS and Flatcar
|
2016-11-28 20:18:06 +08:00
|
|
|
set_fact:
|
|
|
|
bin_dir: "/opt/bin"
|
2020-02-18 16:15:29 +08:00
|
|
|
when: ansible_os_family in ["CoreOS", "Coreos", "Container Linux by CoreOS", "Flatcar", "Flatcar Container Linux by Kinvolk"]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Force binaries directory on other hosts
|
|
|
|
set_fact:
|
2016-11-28 20:18:06 +08:00
|
|
|
bin_dir: "/usr/local/bin"
|
2020-02-18 16:15:29 +08:00
|
|
|
when: not ansible_os_family in ["CoreOS", "Coreos", "Container Linux by CoreOS", "Flatcar", "Flatcar Container Linux by Kinvolk"]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2020-04-01 22:23:29 +08:00
|
|
|
- import_role:
|
|
|
|
name: cluster-dump
|
|
|
|
|
2016-11-28 20:18:06 +08:00
|
|
|
- name: Wait for netchecker server
|
2019-05-03 05:24:21 +08:00
|
|
|
shell: "{{ bin_dir }}/kubectl get pods -o wide --namespace {{ netcheck_namespace }} | grep ^netchecker-server"
|
2016-11-28 20:18:06 +08:00
|
|
|
register: ncs_pod
|
|
|
|
until: ncs_pod.stdout.find('Running') != -1
|
|
|
|
retries: 3
|
|
|
|
delay: 10
|
2020-05-01 14:38:05 +08:00
|
|
|
when: inventory_hostname == groups['kube-master'][0]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
|
|
|
- name: Wait for netchecker agents
|
2019-05-03 05:24:21 +08:00
|
|
|
shell: "{{ bin_dir }}/kubectl get pods -o wide --namespace {{ netcheck_namespace }} | grep '^netchecker-agent-.*Running'"
|
2016-11-28 20:18:06 +08:00
|
|
|
register: nca_pod
|
2019-02-01 06:57:22 +08:00
|
|
|
until: nca_pod.stdout_lines|length >= groups['k8s-cluster']|intersect(ansible_play_hosts)|length * 2
|
2016-11-28 20:18:06 +08:00
|
|
|
retries: 3
|
|
|
|
delay: 10
|
2019-01-26 00:14:22 +08:00
|
|
|
failed_when: false
|
2020-05-01 14:38:05 +08:00
|
|
|
when: inventory_hostname == groups['kube-master'][0]
|
2019-01-26 00:14:22 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Get netchecker pods
|
|
|
|
command: "{{ bin_dir }}/kubectl -n {{ netcheck_namespace }} describe pod -l app={{ item }}"
|
2019-01-26 00:14:22 +08:00
|
|
|
run_once: true
|
2019-05-03 05:24:21 +08:00
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
2019-01-26 00:14:22 +08:00
|
|
|
no_log: false
|
|
|
|
with_items:
|
|
|
|
- netchecker-agent
|
|
|
|
- netchecker-agent-hostnet
|
|
|
|
when: not nca_pod is success
|
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- debug:
|
|
|
|
var: nca_pod.stdout_lines
|
2019-01-26 00:14:22 +08:00
|
|
|
failed_when: not nca_pod is success
|
2020-05-07 02:13:09 +08:00
|
|
|
when: inventory_hostname == groups['kube-master'][0]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
|
|
|
- name: Get netchecker agents
|
2019-05-16 15:27:43 +08:00
|
|
|
uri:
|
|
|
|
url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/agents/"
|
|
|
|
return_content: yes
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
2019-05-03 05:24:21 +08:00
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
register: agents
|
2017-02-20 22:09:34 +08:00
|
|
|
retries: 18
|
2016-11-28 20:18:06 +08:00
|
|
|
delay: "{{ agent_report_interval }}"
|
2018-10-11 15:45:00 +08:00
|
|
|
until: agents.content|length > 0 and
|
2016-11-28 20:18:06 +08:00
|
|
|
agents.content[0] == '{' and
|
2019-02-01 06:57:22 +08:00
|
|
|
agents.content|from_json|length >= groups['k8s-cluster']|intersect(ansible_play_hosts)|length * 2
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2016-11-28 20:18:06 +08:00
|
|
|
no_log: true
|
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- debug:
|
|
|
|
var: agents.content | from_json
|
2018-10-17 06:33:30 +08:00
|
|
|
failed_when: not agents is success and not agents.content=='{}'
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
2019-01-28 19:33:18 +08:00
|
|
|
when:
|
2019-01-29 02:22:43 +08:00
|
|
|
- agents.content is defined
|
2019-04-29 14:00:20 +08:00
|
|
|
- agents.content
|
2019-01-28 19:33:18 +08:00
|
|
|
- agents.content[0] == '{'
|
|
|
|
|
2016-11-28 20:18:06 +08:00
|
|
|
- name: Check netchecker status
|
2019-05-16 15:27:43 +08:00
|
|
|
uri:
|
|
|
|
url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/connectivity_check"
|
|
|
|
status_code: 200
|
|
|
|
return_content: yes
|
2019-05-03 05:24:21 +08:00
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
|
|
|
register: result
|
|
|
|
retries: 3
|
|
|
|
delay: "{{ agent_report_interval }}"
|
2019-01-26 00:14:22 +08:00
|
|
|
until: result.content|length > 0 and
|
|
|
|
result.content[0] == '{'
|
2016-11-28 20:18:06 +08:00
|
|
|
no_log: true
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2018-10-20 19:56:55 +08:00
|
|
|
when:
|
|
|
|
- agents.content != '{}'
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- debug:
|
|
|
|
var: ncs_pod
|
2019-01-26 00:14:22 +08:00
|
|
|
run_once: true
|
|
|
|
when: not result is success
|
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Get kube-proxy logs
|
|
|
|
command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app=kube-proxy"
|
2019-01-26 00:14:22 +08:00
|
|
|
no_log: false
|
2020-05-01 14:38:05 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube-master'][0]
|
|
|
|
- not result is success
|
2019-01-26 00:14:22 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Get logs from other apps
|
|
|
|
command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app={{ item }} --all-containers"
|
2020-05-01 14:38:05 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube-master'][0]
|
|
|
|
- not result is success
|
2019-01-26 00:14:22 +08:00
|
|
|
no_log: false
|
|
|
|
with_items:
|
|
|
|
- kube-router
|
|
|
|
- flannel
|
|
|
|
- contiv-ovs
|
|
|
|
- contiv-netplugin
|
|
|
|
- contiv-netmaster
|
|
|
|
- canal-node
|
|
|
|
- calico-node
|
|
|
|
- cilium
|
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- debug:
|
|
|
|
var: result.content | from_json
|
2018-10-17 06:33:30 +08:00
|
|
|
failed_when: not result is success
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
2019-01-26 00:14:22 +08:00
|
|
|
when:
|
|
|
|
- not agents.content == '{}'
|
2019-04-29 14:00:20 +08:00
|
|
|
- result.content
|
2019-01-26 00:14:22 +08:00
|
|
|
- result.content[0] == '{'
|
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- debug:
|
|
|
|
var: result
|
2019-01-26 00:14:22 +08:00
|
|
|
failed_when: not result is success
|
|
|
|
run_once: true
|
|
|
|
when:
|
|
|
|
- not agents.content == '{}'
|
2016-12-15 17:28:03 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- debug:
|
|
|
|
msg: "Cannot get reports from agents, consider as PASSING"
|
2016-12-15 17:28:03 +08:00
|
|
|
run_once: true
|
2018-10-20 19:56:55 +08:00
|
|
|
when:
|
|
|
|
- agents.content == '{}'
|
2018-11-04 17:07:38 +08:00
|
|
|
|
|
|
|
- name: Create macvlan network conf
|
|
|
|
# We cannot use only shell: below because Ansible will render the text
|
|
|
|
# with leading spaces, which means the shell will never find the string
|
|
|
|
# EOF at the beginning of a line. We can avoid Ansible's unhelpful
|
|
|
|
# heuristics by using the cmd parameter like this:
|
|
|
|
shell:
|
|
|
|
cmd: |
|
|
|
|
cat <<EOF | {{ bin_dir }}/kubectl create -f -
|
|
|
|
apiVersion: "k8s.cni.cncf.io/v1"
|
|
|
|
kind: NetworkAttachmentDefinition
|
|
|
|
metadata:
|
|
|
|
name: macvlan-conf
|
|
|
|
spec:
|
|
|
|
config: '{
|
2020-05-07 02:13:09 +08:00
|
|
|
"cniVersion": "0.4.0",
|
2018-11-04 17:07:38 +08:00
|
|
|
"type": "macvlan",
|
|
|
|
"master": "eth0",
|
|
|
|
"mode": "bridge",
|
|
|
|
"ipam": {
|
|
|
|
"type": "host-local",
|
|
|
|
"subnet": "192.168.1.0/24",
|
|
|
|
"rangeStart": "192.168.1.200",
|
|
|
|
"rangeEnd": "192.168.1.216",
|
|
|
|
"routes": [
|
|
|
|
{ "dst": "0.0.0.0/0" }
|
|
|
|
],
|
|
|
|
"gateway": "192.168.1.1"
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
EOF
|
|
|
|
when:
|
2020-05-01 14:38:05 +08:00
|
|
|
- inventory_hostname == groups['kube-master'][0]
|
2020-06-03 15:00:17 +08:00
|
|
|
- kube_network_plugin_multus|default(false)|bool
|
2018-11-04 17:07:38 +08:00
|
|
|
|
|
|
|
- name: Annotate pod with macvlan network
|
|
|
|
# We cannot use only shell: below because Ansible will render the text
|
|
|
|
# with leading spaces, which means the shell will never find the string
|
|
|
|
# EOF at the beginning of a line. We can avoid Ansible's unhelpful
|
|
|
|
# heuristics by using the cmd parameter like this:
|
|
|
|
shell:
|
|
|
|
cmd: |
|
|
|
|
cat <<EOF | {{ bin_dir }}/kubectl create -f -
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
|
|
|
name: samplepod
|
|
|
|
annotations:
|
|
|
|
k8s.v1.cni.cncf.io/networks: macvlan-conf
|
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: samplepod
|
|
|
|
command: ["/bin/bash", "-c", "sleep 2000000000000"]
|
|
|
|
image: dougbtv/centos-network
|
|
|
|
EOF
|
|
|
|
when:
|
2020-05-01 14:38:05 +08:00
|
|
|
- inventory_hostname == groups['kube-master'][0]
|
2020-06-03 15:00:17 +08:00
|
|
|
- kube_network_plugin_multus|default(false)|bool
|
2018-11-04 17:07:38 +08:00
|
|
|
|
|
|
|
- name: Check secondary macvlan interface
|
|
|
|
shell: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
|
|
|
|
register: output
|
|
|
|
until: output.rc == 0
|
|
|
|
retries: 90
|
|
|
|
changed_when: false
|
|
|
|
when:
|
2020-05-01 14:38:05 +08:00
|
|
|
- inventory_hostname == groups['kube-master'][0]
|
2020-06-03 15:00:17 +08:00
|
|
|
- kube_network_plugin_multus|default(false)|bool
|