调整nfs 动态存储相关脚本

pull/276/head
gjmzj 2018-07-28 10:21:34 +08:00
parent d4a130a59a
commit 5976f61497
12 changed files with 46 additions and 58 deletions

4
.gitignore vendored
View File

@ -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

View File

@ -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:
@ -24,7 +24,7 @@ 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"
@ -32,4 +32,4 @@ spec:
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: test
claimName: test-claim

View File

@ -1,11 +0,0 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
spec:
storageClassName: alicloud-nas
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Mi

View File

@ -1,22 +0,0 @@
kind: Pod
apiVersion: v1
metadata:
name: test-pod
spec:
containers:
- name: test-pod
image: busybox
imagePullPolicy: IfNotPresent
command:
- "/bin/sh"
args:
- "-c"
- "touch /mnt/SUCCESS && exit 0 || exit 1"
volumeMounts:
- name: nfs-pvc
mountPath: "/mnt"
restartPolicy: "Never"
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: test-claim

View File

@ -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信息

View File

@ -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

View File

@ -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

View File

@ -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动态存储
@ -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: 准备部署动态存储类
@ -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"'

View File

@ -41,7 +41,7 @@ roleRef:
kind: Deployment
apiVersion: apps/v1beta1
metadata:
name: nfs-client-provisioner
name: {{ nfs_provisioner_name }}
namespace: kube-system
spec:
replicas: 1
@ -49,11 +49,11 @@ spec:
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:
@ -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 }}

View File

@ -9,6 +9,7 @@
- calico
- cluster-addon
- cluster-restore
- cluster-storage
- flannel
- helm
- kube-node
@ -24,6 +25,7 @@
- calico
- cluster-addon
- cluster-restore
- cluster-storage
- flannel
- helm
- kube-node