Skip to content

Commit

Permalink
Merge pull request #35 from dougbtv/glusterdynamic
Browse files Browse the repository at this point in the history
Gluster dynamic volume provisioning
  • Loading branch information
dougbtv authored Aug 10, 2017
2 parents b9a62bc + 3c01fef commit 2fce185
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 19 deletions.
39 changes: 24 additions & 15 deletions gluster-install.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
---
- hosts: all_vms
become: true
become_user: root
tasks: []
roles:
- { role: glusterfs-install }
# - hosts: all_vms
# become: true
# become_user: root
# tasks: []
# roles:
# - { role: glusterfs-install }

- hosts: master
# - hosts: master
# become: true
# become_user: root
# tasks: []
# roles:
# - { role: glusterfs-probe-peers }
# - { role: glusterfs-create-volume, volume_appendix: 1 }
# - { role: glusterfs-create-volume, volume_appendix: 2 }
# - { role: glusterfs-create-volume, volume_appendix: 3 }
# - { role: glusterfs-create-volume, volume_appendix: 4 }
# - { role: glusterfs-create-volume, volume_appendix: 5 }

- hosts: minions
become: true
become_user: root
tasks: []
roles:
- { role: glusterfs-probe-peers }
- { role: glusterfs-create-volume, volume_appendix: 1 }
- { role: glusterfs-create-volume, volume_appendix: 2 }
- { role: glusterfs-create-volume, volume_appendix: 3 }
- { role: glusterfs-create-volume, volume_appendix: 4 }
- { role: glusterfs-create-volume, volume_appendix: 5 }
tasks:
- name: Install mount.glusterfs
yum:
name: glusterfs-fuse
state: present

- hosts: master
tasks: []
Expand Down
16 changes: 16 additions & 0 deletions gluster-wipe-vg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- hosts: all_vms
become: true
become_user: root
tasks:
- name: Get volume groups
shell: >
vgdisplay | grep "VG Name" | awk '{print $3}'
register: vgoutput

- name: Delete volume groups
shell: >
vgremove {{ vgoutput.stdout }}
when: "'vg_' in vgoutput.stdout"

roles: []

6 changes: 3 additions & 3 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pod_network_cidr: "10.244.0.0"
skip_preflight_checks: true

# Stable. (was busted at 1.6 release, may work now, untested for a couple months)
# kube_baseurl: http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
kube_baseurl: http://yum.kubernetes.io/repos/kubernetes-el7-x86_64

# Unstable
kube_baseurl: http://yum.kubernetes.io/repos/kubernetes-el7-x86_64-unstable
# kube_baseurl: http://yum.kubernetes.io/repos/kubernetes-el7-x86_64-unstable

centos_genericcloud_url: "http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1611.qcow2"
image_destination_name: CentOS-7-x86_64-GenericCloud.qcow2
Expand Down Expand Up @@ -60,7 +60,7 @@ multus_ipam_gateway: "192.168.122.1"
# ----------------------------
# glusterfs vars
# ----------------------------
spare_disk_size_megs: 4096
spare_disk_size_megs: 10240
spare_disk_location: "/var/lib/libvirt/images"
spare_disk_dev: vdb
# Default size is megs, "2G" would be 2 gigs.
Expand Down
99 changes: 98 additions & 1 deletion roles/glusterfs-kube-config/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---

- name: Install git
become: true
become_user: root
yum:
name: git
state: present

- name: Template endpoints json
template:
src: glusterfs-endpoints.json.j2
Expand All @@ -13,4 +20,94 @@
- name: Template volume yaml (IT'S STATIC RIGHT NOW, FIX THAT.)
template:
src: glusterfs-volumes.yaml.j2
dest: /home/centos/glusterfs-volumes.yaml
dest: /home/centos/glusterfs-volumes.yaml

- name: Template namespace yaml
template:
src: glusterfs-namespace.yaml.j2
dest: /home/centos/glusterfs-namespace.yaml

- name: Get list of namespaces
shell: >
kubectl get namespaces
register: namespaces_list

- name: Create gluster namespace if necessary
shell: >
kubectl create -f /home/centos/glusterfs-namespace.yaml
when: "'gluster' not in namespaces_list.stdout"

- name: Clone gluster-kubernetes
git:
repo: https://github.com/gluster/gluster-kubernetes.git
dest: /home/centos/gluster-kubernetes
version: master

- name: Template GlusterFS gk-deploy topology json
template:
src: glusterfs-topology.json.j2
dest: /home/centos/gluster-kubernetes/deploy/topology.json

- name: Download heketi cli tarball
get_url:
url: https://github.com/heketi/heketi/releases/download/v4.0.0/heketi-v4.0.0.linux.amd64.tar.gz
dest: /home/centos/heketi.tar.gz

- name: Create directory for extraction of tarball
file:
path: /home/centos/heketi
state: directory

- name: Extract heketi cli tarball
unarchive:
src: /home/centos/heketi.tar.gz
dest: /home/centos/heketi
remote_src: yes

- name: Copy heketi-cli bin into place
become: true
become_user: root
shell: >
cp /home/centos/heketi/heketi/heketi-cli /usr/local/bin/heketi-cli
args:
creates: /usr/local/bin/heketi-cli

- name: Deploy GlusterFS on Kubernetes with gk-deploy (note -- this is coffee break worthy, it takes a while)
shell: >
./gk-deploy -n gluster -g -y
args:
chdir: /home/centos/gluster-kubernetes/deploy
creates: /home/centos/.gk-deployed

- name: Mark that gk-deploy is complete
file:
path: /home/centos/.gk-deployed
state: directory

- name: Get the heketi IP address
shell: >
kubectl get svc --namespace=gluster | grep 8080 | awk '{print $2}'
register: heketi_ipaddress_raw

- name: Set the heketi IP
set_fact:
heketi_ip: "{{ heketi_ipaddress_raw.stdout }}"

- name: Template the storage class yaml
template:
src: glusterfs-storageclass.yaml.j2
dest: /home/centos/glusterfs-storageclass.yaml

- name: List the storage classes
shell: >
kubectl get storageclass
register: storageclass_list

- name: Create the storage class
shell: >
kubectl create -f /home/centos/glusterfs-storageclass.yaml
when: "'gluster' not in storageclass_list.stdout"

# Get heketi URL.
# [centos@kube-master ~]$ kubectl get svc --namespace=gluster | grep 8080 | awk '{print $2}'
# 10.105.179.111
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: gluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: gluster
provisioner: kubernetes.io/glusterfs
# If it could be resolved, could be improved to:
# resturl: "http://heketi.gluster.svc.cluster.local:8080"
parameters:
resturl: "http://{{ heketi_ip }}:8080"
restuser: "this_is_unused"
restuserkey: "boy_thats_pretty_insecure"
26 changes: 26 additions & 0 deletions roles/glusterfs-kube-config/templates/glusterfs-topology.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"clusters": [
{
"nodes": [
{% for machine in groups['minions'] %}
{
"node": {
"hostnames": {
"manage": [
"{{ machine }}"
],
"storage": [
"{{ hostvars[machine]['ansible_host'] }}"
]
},
"zone": 1
},
"devices": [
"/dev/{{ spare_disk_dev }}"
]
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
]
}

0 comments on commit 2fce185

Please sign in to comment.