From 8b1ce9dcc5563dad67444925a80dce99521484aa Mon Sep 17 00:00:00 2001 From: Ravi Palankar Date: Thu, 20 Jun 2019 00:18:23 +0530 Subject: [PATCH] calico cni choice --- defaults/main.yml | 10 +++++++++- tasks/master-setup.yml | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index f357417..1080144 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -21,7 +21,12 @@ kubernetes_allow_pods_on_master: true kubernetes_enable_web_ui: true kubernetes_web_ui_manifest_file: https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml -kubernetes_pod_network_cidr: '10.244.0.0/16' +kubernetes_cni: 'calico' +kubernetes_pod_network: + - name: 'flannel' + cidr: '10.244.0.0/16' + - name: 'calico' + cidr: '192.168.0.0/16' kubernetes_apiserver_advertise_address: '' kubernetes_version_kubeadm: 'stable-{{ kubernetes_version }}' kubernetes_ignore_preflight_errors: 'all' @@ -36,3 +41,6 @@ kubernetes_yum_arch: x86_64 # Flannel config files. kubernetes_flannel_manifest_file_rbac: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml kubernetes_flannel_manifest_file: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml + +# Calico config files +kubernetes_calico_manifest_file: https://docs.projectcalico.org/v3.7/manifests/calico.yaml diff --git a/tasks/master-setup.yml b/tasks/master-setup.yml index c6631c7..0c4ffda 100644 --- a/tasks/master-setup.yml +++ b/tasks/master-setup.yml @@ -2,15 +2,15 @@ - name: Initialize Kubernetes master with kubeadm init. command: > kubeadm init - --pod-network-cidr={{ kubernetes_pod_network_cidr }} + --pod-network-cidr={{ item.cidr }} --apiserver-advertise-address={{ kubernetes_apiserver_advertise_address | default(ansible_default_ipv4.address, true) }} --kubernetes-version {{ kubernetes_version_kubeadm }} --ignore-preflight-errors={{ kubernetes_ignore_preflight_errors }} {{ kubernetes_kubeadm_init_extra_opts }} - + with_items: "{{ kubernetes_pod_network }}" register: kubeadmin_init failed_when: false - when: not kubernetes_init_stat.stat.exists + when: not kubernetes_init_stat.stat.exists and item.name == kubernetes_cni - name: Print the init output to screen. debug: @@ -36,6 +36,15 @@ - kubectl apply -f {{ kubernetes_flannel_manifest_file }} register: flannel_result changed_when: "'created' in flannel_result.stdout" + when: kubernetes_cni == 'flannel' + +- name: Configure Calico networking. + command: "{{ item }}" + with_items: + - kubectl apply -f {{ kubernetes_calico_manifest_file }} + register: calico_result + changed_when: "'created' in calico_result.stdout" + when: kubernetes_cni == 'calico' # TODO: Check if taint exists with something like `kubectl describe nodes` # instead of using kubernetes_init_stat.stat.exists check.