Skip to content

Commit

Permalink
[CE-366] Add persistent volume for k8s
Browse files Browse the repository at this point in the history
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 <litong01@us.ibm.com>
  • Loading branch information
Tong Li committed May 18, 2018
1 parent f6f8127 commit 6b1b614
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/agent/ansible/roles/env_k8s/master/tasks/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/agent/ansible/roles/env_k8s/post/tasks/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
with_items:
- dnscontroller
- dashboard
- pv

- name: Label the master node
command: >-
Expand All @@ -31,18 +32,29 @@
{{ 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
-f /etc/kubernetes/{{ item }}.yaml
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"
Expand Down
14 changes: 14 additions & 0 deletions src/agent/ansible/roles/env_k8s/post/templates/pv.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: k8spv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
nfs:
path: /
server: {{ private_ip }}
persistentVolumeReclaimPolicy: Recycle
4 changes: 4 additions & 0 deletions src/agent/ansible/roles/env_k8s/worker/tasks/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down

0 comments on commit 6b1b614

Please sign in to comment.