calico cni choice

This commit is contained in:
Ravi Palankar 2019-06-20 00:18:23 +05:30
parent ae8f596e8f
commit 8b1ce9dcc5
2 changed files with 21 additions and 4 deletions

View File

@ -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

View File

@ -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.