Skip to content

Commit

Permalink
refactroing ansible part
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Utkin committed Oct 2, 2019
1 parent 4860b29 commit 9a103bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IMAGE_NAME = "bento/ubuntu-18.04"
N = 1
CNI_PLUGIN = "calico"
CNI_PLUGIN = "flannel"
DOCKER_VERSION = "5:18.09"
K8S_VERSION = "1.15"

Expand Down
2 changes: 2 additions & 0 deletions provision/kubernetes-setup/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- name: docker status
service: name=docker state=started
42 changes: 23 additions & 19 deletions provision/kubernetes-setup/master-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
become: true
vars:
cni_plugin: calico
pod_network_cidr: >
{{ (cni_plugin == 'flannel' or cni_plugin == 'canal') | ternary('10.244.0.0/16', '192.168.0.0/16') }}
calico_manifest_uri: https://docs.projectcalico.org/v3.8/manifests/calico.yaml
flannel_manifest_uri: "https://raw.githubusercontent.com/coreos/flannel/\
62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml"
canal_manifest_uri: https://docs.projectcalico.org/v3.8/manifests/canal.yaml
k8s_network_config:
calico:
pod_network_cidr: '192.168.0.0/16'
manifest_uri: "{{ calico_manifest_uri }}"
flannel:
pod_network_cidr: '10.244.0.0/16'
manifest_uri: "{{ flannel_manifest_uri }}"
canal:
pod_network_cidr: '10.244.0.0/16'
manifest_uri: "{{ canal_manifest_uri }}"
docker_version: latest
k8s_version: latest
tasks:
Expand All @@ -17,6 +29,10 @@
kubeadm init --apiserver-advertise-address="192.168.50.10"
--apiserver-cert-extra-sans="192.168.50.10" --node-name k8s-master
--pod-network-cidr={{ pod_network_cidr }}
args:
creates: /etc/kubernetes/admin.conf
vars:
pod_network_cidr: "{{ k8s_network_config[cni_plugin]['pod_network_cidr'] }}"

- name: Setup kubeconfig for vagrant user
command: "{{ item }}"
Expand All @@ -25,23 +41,12 @@
- cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
- chown vagrant:vagrant /home/vagrant/.kube/config

- name: Install calico pod network
- name: Install {{ cni_plugin }} pod network
become: false
command: >
kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml
when: cni_plugin == 'calico'

- name: Install flannel pod network
become: false
command: >
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml
when: cni_plugin == 'flannel'

- name: Install canal pod network
become: false
command: >
kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/canal.yaml
when: cni_plugin == 'canal'
kubectl apply -f {{ manifest_uri }}
vars:
manifest_uri: "{{ k8s_network_config[cni_plugin]['manifest_uri'] }}"

- name: Generate join command
command: kubeadm token create --print-join-command
Expand All @@ -51,5 +56,4 @@
local_action: copy content="{{ join_command.stdout_lines[0] }}" dest="/vagrant/join-command"

handlers:
- name: docker status
service: name=docker state=started
- import_tasks: handlers/main.yml
3 changes: 1 addition & 2 deletions provision/kubernetes-setup/node-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
command: sh /tmp/join-command.sh

handlers:
- name: docker status
service: name=docker state=started
- import_tasks: handlers/main.yml

0 comments on commit 9a103bc

Please sign in to comment.