From 6b1b614bda0750c698646292f568e2a5a98e9f87 Mon Sep 17 00:00:00 2001 From: Tong Li Date: Thu, 17 May 2018 21:39:36 -0400 Subject: [PATCH] [CE-366] Add persistent volume for k8s Currently ansible agent does not provide persistent volume for created k8s env. This patch will add that capability. It will create a nfs based persistent volume. Change-Id: I3ec80b04a74b54193cc5b445b4b4024967662d4b Signed-off-by: Tong Li --- .../ansible/roles/env_k8s/master/tasks/apply.yml | 2 -- .../ansible/roles/env_k8s/post/tasks/apply.yml | 14 +++++++++++++- .../ansible/roles/env_k8s/post/templates/pv.j2 | 14 ++++++++++++++ .../ansible/roles/env_k8s/worker/tasks/apply.yml | 4 ++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100755 src/agent/ansible/roles/env_k8s/post/templates/pv.j2 diff --git a/src/agent/ansible/roles/env_k8s/master/tasks/apply.yml b/src/agent/ansible/roles/env_k8s/master/tasks/apply.yml index 3f0e5b16..1656bbd2 100755 --- a/src/agent/ansible/roles/env_k8s/master/tasks/apply.yml +++ b/src/agent/ansible/roles/env_k8s/master/tasks/apply.yml @@ -125,8 +125,6 @@ template: src: "{{ playbook_dir }}/../env_k8s/master/templates/kubeconfig.j2" dest: "/etc/kubernetes/kubeconfig" - mode: 0600 - become: false tags: "kubeconfig" - name: Get the kubeconfig to the ansible controller diff --git a/src/agent/ansible/roles/env_k8s/post/tasks/apply.yml b/src/agent/ansible/roles/env_k8s/post/tasks/apply.yml index d4b6dea0..dee6195f 100755 --- a/src/agent/ansible/roles/env_k8s/post/tasks/apply.yml +++ b/src/agent/ansible/roles/env_k8s/post/tasks/apply.yml @@ -20,6 +20,7 @@ with_items: - dnscontroller - dashboard + - pv - name: Label the master node command: >- @@ -31,6 +32,17 @@ {{ fabricroot }}/bin/kubectl --server={{ private_ip }}:8080 create secret generic kubernetes-dashboard-certs --from-file=/etc/kubernetes/secrets/certs -n kube-system +- name: Ensure NFS directory exists + file: + path: /opt/k8spv + state: directory + +- name: Launch NFS server + command: >- + docker run -d --name nfs --privileged --net=host + -v /opt/k8spv:/nfsshare -e SHARED_DIRECTORY=/nfsshare + itsthenetwork/nfs-server-alpine:latest + - name: Create addon services command: >- {{ fabricroot }}/bin/kubectl --server={{ private_ip }}:8080 apply @@ -38,11 +50,11 @@ with_items: - dnscontroller - dashboard + - pv # The following code setup a native docker nginx container to # proxy dns lookup to k8s dns services so that containers # created by docker containers can also use names - - name: Upload nginx configuration file template: src: "{{ playbook_dir }}/../env_k8s/post/templates/nginx.j2" diff --git a/src/agent/ansible/roles/env_k8s/post/templates/pv.j2 b/src/agent/ansible/roles/env_k8s/post/templates/pv.j2 new file mode 100755 index 00000000..247f0d55 --- /dev/null +++ b/src/agent/ansible/roles/env_k8s/post/templates/pv.j2 @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: k8spv +spec: + capacity: + storage: 5Gi + accessModes: + - ReadWriteOnce + nfs: + path: / + server: {{ private_ip }} + persistentVolumeReclaimPolicy: Recycle diff --git a/src/agent/ansible/roles/env_k8s/worker/tasks/apply.yml b/src/agent/ansible/roles/env_k8s/worker/tasks/apply.yml index db4b29e8..ed4aebdb 100755 --- a/src/agent/ansible/roles/env_k8s/worker/tasks/apply.yml +++ b/src/agent/ansible/roles/env_k8s/worker/tasks/apply.yml @@ -6,6 +6,10 @@ service_path: "/lib/systemd/system/" fabricroot: "/opt/fabric" +- name: Install nfs-common + apt: + name: nfs-common + - name: Ensure binary directory exists file: path: "{{ item }}"