Skip to content

Commit

Permalink
调整nfs 动态存储相关脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmzj committed Jul 28, 2018
1 parent d4a130a commit 5976f61
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ manifests/coredns/coredns.yaml
# ansible hosts
hosts

# k8s storage manifests
manifests/storage/*
!manifests/storage/test.yaml

# k8s backup directory
roles/cluster-backup/files/*
!roles/cluster-backup/files/readme.md
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test
name: test-claim
spec:
storageClassName: alicloud-nas
storageClassName: nfs-dynamic-class-01
accessModes:
- ReadWriteMany
resources:
Expand All @@ -24,12 +24,12 @@ spec:
- "/bin/sh"
args:
- "-c"
- "touch /mnt/YES && exit 0 || exit 1"
- "echo 'hello k8s' > /mnt/SUCCESS && sleep 36000 || exit 1"
volumeMounts:
- name: nfs-pvc
mountPath: "/mnt"
restartPolicy: "Never"
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: test
claimName: test-claim
11 changes: 0 additions & 11 deletions manifests/storage/test/test-claim.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions manifests/storage/test/test-pod.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions roles/cluster-addon/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#-------------kube-dns 插件参数初始化
# kubedns.yaml文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
- name: 准备 kubedns的部署文件 kubedns.yaml
template: src=dns/kubedns.yaml.j2 dest={{ base_dir }}/manifests/kubedns/kubedns.yaml
template: src=kubedns.yaml.j2 dest={{ base_dir }}/manifests/kubedns/kubedns.yaml
when: "hostvars[inventory_hostname]['group_names'].count('deploy') == 1"

# coredns.yaml文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
- name: 准备 coredns的部署文件 coredns.yaml
template: src=dns/coredns.yaml.j2 dest={{ base_dir }}/manifests/coredns/coredns.yaml
template: src=coredns.yaml.j2 dest={{ base_dir }}/manifests/coredns/coredns.yaml
when: "hostvars[inventory_hostname]['group_names'].count('deploy') == 1"

- name: 获取所有已经创建的POD信息
Expand Down
5 changes: 0 additions & 5 deletions roles/cluster-storage/cluster-storage.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
- 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
13 changes: 11 additions & 2 deletions roles/cluster-storage/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# 动态存储类型, 目前支持nfs和alicloud-nas
storage_type: nfs
# 动态存储类型, 目前支持自建nfs和aliyun_nas
storage_nfs_enabled: "no"
storage_aliyun_nas_enabled: "no"

# nfs server 参数
nfs_server: "192.168.1.8"
nfs_server_path: "/data/nfs"
nfs_storage_class: "nfs-dynamic-class-01"
nfs_provisioner_name: "nfs-provisioner-01"

# aliyun_nas 参数
storage_server: 172.16.3.86
storage_path: /data/nfs
storage_class_name: nfs-dynamic-class
11 changes: 7 additions & 4 deletions roles/cluster-storage/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
- block:
- name: 准备nfs-client 配置目录
file: name={{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }} state=directory
- name: 准备部署nfs-client动态存储
template:
src: nfs/nfs-client-provisioner.yaml.j2
dest: "{{ base_dir }}/manifests/storage/nfs/nfs-client-provisioner.yaml"
dest: "{{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }}/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"'
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }}"
when: 'storage_nfs_enabled == "yes"'

- block:
- name: 准备部署alicloud-nas动态存储
Expand All @@ -16,7 +18,7 @@
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"'
when: 'storage_aliyun_nas_enabled == "yes"'

- block:
- name: 准备部署动态存储类
Expand All @@ -25,3 +27,4 @@
dest: "{{ base_dir }}/manifests/storage/dynamic-storageclass.yaml"
- name: 开始部署动态存储类
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/dynamic-storageclass.yaml"
when: 'storage_aliyun_nas_enabled == "yes"'
24 changes: 16 additions & 8 deletions roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ roleRef:
kind: Deployment
apiVersion: apps/v1beta1
metadata:
name: nfs-client-provisioner
name: {{ nfs_provisioner_name }}
namespace: kube-system
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client-provisioner
app: {{ nfs_provisioner_name }}
template:
metadata:
labels:
app: nfs-client-provisioner
app: {{ nfs_provisioner_name }}
spec:
serviceAccountName: nfs-client-provisioner
containers:
Expand All @@ -67,13 +67,21 @@ spec:
env:
- name: PROVISIONER_NAME
# 此处供应者名字供storageclass调用
value: prov
value: {{ nfs_provisioner_name }}
- name: NFS_SERVER
value: {{ storage_server }}
value: {{ nfs_server }}
- name: NFS_PATH
value: {{ storage_path }}
value: {{ nfs_server_path }}
volumes:
- name: nfs-client-root
nfs:
server: {{ storage_server }}
path: {{ storage_path }}
server: {{ nfs_server }}
path: {{ nfs_server_path }}

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: {{ nfs_storage_class }}
provisioner: {{ nfs_provisioner_name }}

2 changes: 2 additions & 0 deletions tools/init_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- calico
- cluster-addon
- cluster-restore
- cluster-storage
- flannel
- helm
- kube-node
Expand All @@ -24,6 +25,7 @@
- calico
- cluster-addon
- cluster-restore
- cluster-storage
- flannel
- helm
- kube-node
Expand Down

0 comments on commit 5976f61

Please sign in to comment.