From 4750465c8165a6e2e6804ce3f57d060cbec8563b Mon Sep 17 00:00:00 2001 From: lusyoe Date: Wed, 25 Jul 2018 18:25:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0cluster-storage=20roles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08.cluster-storage.yml | 5 ++++ roles/cluster-addon/defaults/main.yml | 5 ---- roles/cluster-addon/tasks/main.yml | 29 ------------------- roles/cluster-storage/cluster-storage.yml | 8 +++++ roles/cluster-storage/defaults/main.yml | 5 ++++ roles/cluster-storage/tasks/main.yml | 27 +++++++++++++++++ .../alicloud-nas/alicloud-nas.yaml.j2 | 8 ++--- .../templates}/dynamic-storageclass.yaml.j2 | 2 +- .../nfs/nfs-client-provisioner.yaml.j2 | 8 ++--- 9 files changed, 54 insertions(+), 43 deletions(-) create mode 100644 08.cluster-storage.yml create mode 100644 roles/cluster-storage/cluster-storage.yml create mode 100644 roles/cluster-storage/defaults/main.yml create mode 100644 roles/cluster-storage/tasks/main.yml rename roles/{cluster-addon/templates/storage => cluster-storage/templates}/alicloud-nas/alicloud-nas.yaml.j2 (88%) rename roles/{cluster-addon/templates/storage => cluster-storage/templates}/dynamic-storageclass.yaml.j2 (69%) rename roles/{cluster-addon/templates/storage => cluster-storage/templates}/nfs/nfs-client-provisioner.yaml.j2 (92%) diff --git a/08.cluster-storage.yml b/08.cluster-storage.yml new file mode 100644 index 0000000..f88ff12 --- /dev/null +++ b/08.cluster-storage.yml @@ -0,0 +1,5 @@ +- hosts: + - deploy + - kube-node + roles: + - cluster-storage diff --git a/roles/cluster-addon/defaults/main.yml b/roles/cluster-addon/defaults/main.yml index e34ab75..a8ffe85 100644 --- a/roles/cluster-addon/defaults/main.yml +++ b/roles/cluster-addon/defaults/main.yml @@ -26,8 +26,3 @@ heapster_offline: "heapster_v1.5.1.tar" # prometheus 自动安装 #prometheus_install: "no" - -# 动态存储自动安装 -nfsclient_install: "no" -alicloudnas_install: "no" -storage_install: "no" diff --git a/roles/cluster-addon/tasks/main.yml b/roles/cluster-addon/tasks/main.yml index 022b2d4..cfee385 100644 --- a/roles/cluster-addon/tasks/main.yml +++ b/roles/cluster-addon/tasks/main.yml @@ -79,32 +79,3 @@ when: '"heapster" not in pod_info.stdout and heapster_install == "yes"' ignore_errors: true -- block: - - name: 准备部署nfs-client动态存储 - template: - src: storage/nfs/nfs-client-provisioner.yaml.j2 - dest: "{{ base_dir }}/manifests/storage/nfs/nfs-client-provisioner.yaml" - - name: 开始部署nfs-client动态存储 - shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/nfs-client-provisioner.yaml" - when: 'nfsclient_install == "yes"' - -- block: - - name: 准备部署alicloud-nas动态存储 - template: - src: storage/alicloud-nas/alicloud-nas.yaml.j2 - dest: "{{ base_dir }}/manifests/storage/alicloud-nas/alicloud-nas.yaml" - - name: 开始部署alicloud-disk存储 - shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-disk.yaml" - - name: 开始部署alicloud-nas动态存储 - shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-nas.yaml" - when: 'alicloudnas_install == "yes"' - -- block: - - name: 准备部署动态存储类 - template: - src: storage/dynamic-storageclass.yaml.j2 - dest: "{{ base_dir }}/manifests/storage/dynamic-storageclass.yaml" - - name: 开始部署动态存储类 - shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/dynamic-storageclass.yaml" - when: 'storage_install == "yes"' - diff --git a/roles/cluster-storage/cluster-storage.yml b/roles/cluster-storage/cluster-storage.yml new file mode 100644 index 0000000..e0b6d2b --- /dev/null +++ b/roles/cluster-storage/cluster-storage.yml @@ -0,0 +1,8 @@ +hosts: deploy + roles: + - cluster-storage + vars: + storage_type: nfs + storage_server: 172.16.3.86 + storage_path: /data/nfs + storage_class_name: nfs-dynamic-class diff --git a/roles/cluster-storage/defaults/main.yml b/roles/cluster-storage/defaults/main.yml new file mode 100644 index 0000000..86fbe2d --- /dev/null +++ b/roles/cluster-storage/defaults/main.yml @@ -0,0 +1,5 @@ +# 动态存储类型, 目前支持nfs和alicloud-nas +storage_type: nfs +storage_server: 172.16.3.86 +storage_path: /data/nfs +storage_class_name: nfs-dynamic-class diff --git a/roles/cluster-storage/tasks/main.yml b/roles/cluster-storage/tasks/main.yml new file mode 100644 index 0000000..73d6975 --- /dev/null +++ b/roles/cluster-storage/tasks/main.yml @@ -0,0 +1,27 @@ +- block: + - name: 准备部署nfs-client动态存储 + template: + src: nfs/nfs-client-provisioner.yaml.j2 + dest: "{{ base_dir }}/manifests/storage/nfs/nfs-client-provisioner.yaml" + - name: 开始部署nfs-client动态存储 + shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/nfs-client-provisioner.yaml" + when: 'storage_type == "nfs"' + +- block: + - name: 准备部署alicloud-nas动态存储 + template: + src: alicloud-nas/alicloud-nas.yaml.j2 + dest: "{{ base_dir }}/manifests/storage/alicloud-nas/alicloud-nas.yaml" + - name: 开始部署alicloud-disk存储 + shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-disk.yaml" + - name: 开始部署alicloud-nas动态存储 + shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-nas.yaml" + when: 'storage_type == "alicloud-nas"' + +- block: + - name: 准备部署动态存储类 + template: + src: dynamic-storageclass.yaml.j2 + dest: "{{ base_dir }}/manifests/storage/dynamic-storageclass.yaml" + - name: 开始部署动态存储类 + shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/dynamic-storageclass.yaml" diff --git a/roles/cluster-addon/templates/storage/alicloud-nas/alicloud-nas.yaml.j2 b/roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 similarity index 88% rename from roles/cluster-addon/templates/storage/alicloud-nas/alicloud-nas.yaml.j2 rename to roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 index 5dece7c..ea2d5e4 100644 --- a/roles/cluster-addon/templates/storage/alicloud-nas/alicloud-nas.yaml.j2 +++ b/roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 @@ -48,11 +48,11 @@ spec: - name: PROVISIONER_NAME value: alicloud/nas - name: NFS_SERVER - value: {{ STORAGE_SERVER }} + value: {{ storage_server }} - name: NFS_PATH - value: {{ STORAGE_PATH }} + value: {{ storage_path }} volumes: - name: nfs-client-root nfs: - server: {{ STORAGE_SERVER }} - path: {{ STORAGE_PATH }} + server: {{ storage_server }} + path: {{ storage_path }} diff --git a/roles/cluster-addon/templates/storage/dynamic-storageclass.yaml.j2 b/roles/cluster-storage/templates/dynamic-storageclass.yaml.j2 similarity index 69% rename from roles/cluster-addon/templates/storage/dynamic-storageclass.yaml.j2 rename to roles/cluster-storage/templates/dynamic-storageclass.yaml.j2 index e7ad14d..a8a21cd 100644 --- a/roles/cluster-addon/templates/storage/dynamic-storageclass.yaml.j2 +++ b/roles/cluster-storage/templates/dynamic-storageclass.yaml.j2 @@ -1,5 +1,5 @@ apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: - name: {{ STORAGE_CLASS_NAME }} + name: {{ storage_class_name }} provisioner: prov diff --git a/roles/cluster-addon/templates/storage/nfs/nfs-client-provisioner.yaml.j2 b/roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 similarity index 92% rename from roles/cluster-addon/templates/storage/nfs/nfs-client-provisioner.yaml.j2 rename to roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 index ac8877f..cd3351d 100644 --- a/roles/cluster-addon/templates/storage/nfs/nfs-client-provisioner.yaml.j2 +++ b/roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 @@ -69,11 +69,11 @@ spec: # 此处供应者名字供storageclass调用 value: prov - name: NFS_SERVER - value: {{ STORAGE_SERVER }} + value: {{ storage_server }} - name: NFS_PATH - value: {{ STORAGE_PATH }} + value: {{ storage_path }} volumes: - name: nfs-client-root nfs: - server: {{ STORAGE_SERVER }} - path: {{ STORAGE_PATH }} + server: {{ storage_server }} + path: {{ storage_path }}