mirror of https://github.com/easzlab/kubeasz.git
调整nfs 动态存储相关脚本
parent
d4a130a59a
commit
5976f61497
|
@ -13,6 +13,10 @@ manifests/coredns/coredns.yaml
|
||||||
# ansible hosts
|
# ansible hosts
|
||||||
hosts
|
hosts
|
||||||
|
|
||||||
|
# k8s storage manifests
|
||||||
|
manifests/storage/*
|
||||||
|
!manifests/storage/test.yaml
|
||||||
|
|
||||||
# k8s backup directory
|
# k8s backup directory
|
||||||
roles/cluster-backup/files/*
|
roles/cluster-backup/files/*
|
||||||
!roles/cluster-backup/files/readme.md
|
!roles/cluster-backup/files/readme.md
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
metadata:
|
metadata:
|
||||||
name: test
|
name: test-claim
|
||||||
spec:
|
spec:
|
||||||
storageClassName: alicloud-nas
|
storageClassName: nfs-dynamic-class-01
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteMany
|
- ReadWriteMany
|
||||||
resources:
|
resources:
|
||||||
|
@ -24,7 +24,7 @@ spec:
|
||||||
- "/bin/sh"
|
- "/bin/sh"
|
||||||
args:
|
args:
|
||||||
- "-c"
|
- "-c"
|
||||||
- "touch /mnt/YES && exit 0 || exit 1"
|
- "echo 'hello k8s' > /mnt/SUCCESS && sleep 36000 || exit 1"
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: nfs-pvc
|
- name: nfs-pvc
|
||||||
mountPath: "/mnt"
|
mountPath: "/mnt"
|
||||||
|
@ -32,4 +32,4 @@ spec:
|
||||||
volumes:
|
volumes:
|
||||||
- name: nfs-pvc
|
- name: nfs-pvc
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
claimName: test
|
claimName: test-claim
|
|
@ -1,11 +0,0 @@
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
apiVersion: v1
|
|
||||||
metadata:
|
|
||||||
name: test-claim
|
|
||||||
spec:
|
|
||||||
storageClassName: alicloud-nas
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 1Mi
|
|
|
@ -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
|
|
|
@ -1,12 +1,12 @@
|
||||||
#-------------kube-dns 插件参数初始化
|
#-------------kube-dns 插件参数初始化
|
||||||
# kubedns.yaml文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
|
# kubedns.yaml文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
|
||||||
- name: 准备 kubedns的部署文件 kubedns.yaml
|
- 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"
|
when: "hostvars[inventory_hostname]['group_names'].count('deploy') == 1"
|
||||||
|
|
||||||
# coredns.yaml文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
|
# coredns.yaml文件中部分参数根据hosts文件设置而定,因此需要用template模块替换参数
|
||||||
- name: 准备 coredns的部署文件 coredns.yaml
|
- 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"
|
when: "hostvars[inventory_hostname]['group_names'].count('deploy') == 1"
|
||||||
|
|
||||||
- name: 获取所有已经创建的POD信息
|
- name: 获取所有已经创建的POD信息
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
- hosts: deploy
|
- hosts: deploy
|
||||||
roles:
|
roles:
|
||||||
- cluster-storage
|
- cluster-storage
|
||||||
vars:
|
|
||||||
storage_type: nfs
|
|
||||||
storage_server: 172.16.3.86
|
|
||||||
storage_path: /data/nfs
|
|
||||||
storage_class_name: nfs-dynamic-class
|
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
# 动态存储类型, 目前支持nfs和alicloud-nas
|
# 动态存储类型, 目前支持自建nfs和aliyun_nas
|
||||||
storage_type: nfs
|
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_server: 172.16.3.86
|
||||||
storage_path: /data/nfs
|
storage_path: /data/nfs
|
||||||
storage_class_name: nfs-dynamic-class
|
storage_class_name: nfs-dynamic-class
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
- block:
|
- block:
|
||||||
|
- name: 准备nfs-client 配置目录
|
||||||
|
file: name={{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }} state=directory
|
||||||
- name: 准备部署nfs-client动态存储
|
- name: 准备部署nfs-client动态存储
|
||||||
template:
|
template:
|
||||||
src: nfs/nfs-client-provisioner.yaml.j2
|
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动态存储
|
- name: 开始部署nfs-client动态存储
|
||||||
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/nfs-client-provisioner.yaml"
|
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }}"
|
||||||
when: 'storage_type == "nfs"'
|
when: 'storage_nfs_enabled == "yes"'
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: 准备部署alicloud-nas动态存储
|
- name: 准备部署alicloud-nas动态存储
|
||||||
|
@ -16,7 +18,7 @@
|
||||||
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-disk.yaml"
|
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-disk.yaml"
|
||||||
- name: 开始部署alicloud-nas动态存储
|
- name: 开始部署alicloud-nas动态存储
|
||||||
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/alicloud-nas.yaml"
|
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:
|
- block:
|
||||||
- name: 准备部署动态存储类
|
- name: 准备部署动态存储类
|
||||||
|
@ -25,3 +27,4 @@
|
||||||
dest: "{{ base_dir }}/manifests/storage/dynamic-storageclass.yaml"
|
dest: "{{ base_dir }}/manifests/storage/dynamic-storageclass.yaml"
|
||||||
- name: 开始部署动态存储类
|
- name: 开始部署动态存储类
|
||||||
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/dynamic-storageclass.yaml"
|
shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/dynamic-storageclass.yaml"
|
||||||
|
when: 'storage_aliyun_nas_enabled == "yes"'
|
||||||
|
|
|
@ -41,7 +41,7 @@ roleRef:
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta1
|
||||||
metadata:
|
metadata:
|
||||||
name: nfs-client-provisioner
|
name: {{ nfs_provisioner_name }}
|
||||||
namespace: kube-system
|
namespace: kube-system
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
|
@ -49,11 +49,11 @@ spec:
|
||||||
type: Recreate
|
type: Recreate
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: nfs-client-provisioner
|
app: {{ nfs_provisioner_name }}
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: nfs-client-provisioner
|
app: {{ nfs_provisioner_name }}
|
||||||
spec:
|
spec:
|
||||||
serviceAccountName: nfs-client-provisioner
|
serviceAccountName: nfs-client-provisioner
|
||||||
containers:
|
containers:
|
||||||
|
@ -67,13 +67,21 @@ spec:
|
||||||
env:
|
env:
|
||||||
- name: PROVISIONER_NAME
|
- name: PROVISIONER_NAME
|
||||||
# 此处供应者名字供storageclass调用
|
# 此处供应者名字供storageclass调用
|
||||||
value: prov
|
value: {{ nfs_provisioner_name }}
|
||||||
- name: NFS_SERVER
|
- name: NFS_SERVER
|
||||||
value: {{ storage_server }}
|
value: {{ nfs_server }}
|
||||||
- name: NFS_PATH
|
- name: NFS_PATH
|
||||||
value: {{ storage_path }}
|
value: {{ nfs_server_path }}
|
||||||
volumes:
|
volumes:
|
||||||
- name: nfs-client-root
|
- name: nfs-client-root
|
||||||
nfs:
|
nfs:
|
||||||
server: {{ storage_server }}
|
server: {{ nfs_server }}
|
||||||
path: {{ storage_path }}
|
path: {{ nfs_server_path }}
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: storage.k8s.io/v1
|
||||||
|
kind: StorageClass
|
||||||
|
metadata:
|
||||||
|
name: {{ nfs_storage_class }}
|
||||||
|
provisioner: {{ nfs_provisioner_name }}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
- calico
|
- calico
|
||||||
- cluster-addon
|
- cluster-addon
|
||||||
- cluster-restore
|
- cluster-restore
|
||||||
|
- cluster-storage
|
||||||
- flannel
|
- flannel
|
||||||
- helm
|
- helm
|
||||||
- kube-node
|
- kube-node
|
||||||
|
@ -24,6 +25,7 @@
|
||||||
- calico
|
- calico
|
||||||
- cluster-addon
|
- cluster-addon
|
||||||
- cluster-restore
|
- cluster-restore
|
||||||
|
- cluster-storage
|
||||||
- flannel
|
- flannel
|
||||||
- helm
|
- helm
|
||||||
- kube-node
|
- kube-node
|
||||||
|
|
Loading…
Reference in New Issue