diff --git a/docs/08-cluster-storage.md b/docs/08-cluster-storage.md index a82cab5..8d82b16 100644 --- a/docs/08-cluster-storage.md +++ b/docs/08-cluster-storage.md @@ -51,11 +51,13 @@ $ ansible-playbook /etc/ansible/tools/init_vars.yml ``` bash # 比如创建nfs provisioner -storage_nfs_enabled: "yes" -nfs_server: "192.168.1.8" -nfs_server_path: "/data/nfs" -nfs_storage_class: "class-nfs-01" -nfs_provisioner_name: "nfs-provisioner-01" +storage: + nfs: + enabled: "yes" + server: "192.168.1.8" + server_path: "/data/nfs" + storage_class: "class-nfs-01" + provisioner_name: "nfs-provisioner-01" ``` - 3.创建 nfs provisioner diff --git a/docs/guide/efk.md b/docs/guide/efk.md index ddbdc46..1c479d2 100644 --- a/docs/guide/efk.md +++ b/docs/guide/efk.md @@ -135,7 +135,7 @@ es0 es1 es2 #### 使用动态 PV安装 EFK -- 首先根据[这里](nfs-client.md)创建nfs-client-provisioner +- 首先根据[集群存储](../08-cluster-storage.md)创建nfs-client-provisioner - 然后按实际需求修改 `es-dynamic-pv/es-statefulset.yaml` 文件中 volumeClaimTemplates 设置的 storage: 4Gi 大小 ``` bash diff --git a/docs/guide/jenkins.md b/docs/guide/jenkins.md index 81a0e61..f362430 100644 --- a/docs/guide/jenkins.md +++ b/docs/guide/jenkins.md @@ -10,7 +10,9 @@ - helm 为了简化部署,通过helm来安装Jenkins,可参考文档:[helm](helm.md) - 持久化存储 -这里使用**NFS**演示,参考文档:[nfs-client](nfs-client.md)。如果k8s集群是部署在公有云,也可使用厂商的NAS等存储方案,具体参考相关厂商文档 +这里使用**NFS**演示,参考文档:[cluster-storage](../08-cluster-storage.md)。 +如果k8s集群是部署在公有云,也可使用厂商的NAS等存储方案,项目中已集成支持阿里云NAS,其他的方案参考相关厂商文档 + - Ingress Controller(nginx-ingress/traefik) 默认是通过Ingress访问Jenkins,因此需要安装一种`Ingress Controller`。参考文档:[ingress](ingress.md) - Gitlab 代码管理仓库 @@ -175,4 +177,4 @@ http://admin:a910b1492e39e9dd1ea48ea7f7638aaf@jenkins.local.com/project/k8s-test - 使用`kubectl`容器,部署`k8s-example`应用(这里后面也可以使用helm) 访问: -项目通过Ingress访问`k8s-example.com`,出现`hello, world`,就表示服务部署成功了。 \ No newline at end of file +项目通过Ingress访问`k8s-example.com`,出现`hello, world`,就表示服务部署成功了。 diff --git a/roles/cluster-storage/defaults/main.yml b/roles/cluster-storage/defaults/main.yml index d3c4271..2c6a9b9 100644 --- a/roles/cluster-storage/defaults/main.yml +++ b/roles/cluster-storage/defaults/main.yml @@ -1,15 +1,17 @@ # 动态存储类型, 目前支持自建nfs和aliyun_nas -storage_nfs_enabled: "no" -storage_aliyun_nas_enabled: "no" +storage: + # nfs server 参数 + nfs: + enabled: "no" + server: "172.16.3.86" + server_path: "/data/nfs" + storage_class: "nfs-dynamic-class" + provisioner_name: "nfs-provisioner-01" -# nfs server 参数 -nfs_server: "192.168.1.8" -nfs_server_path: "/data/nfs" -nfs_storage_class: "class-nfs-01" -nfs_provisioner_name: "nfs-provisioner-01" - -# aliyun_nas 参数 -aliyun_nas_server: "172.16.3.86" -aliyun_nas_server_path: "/data/nas" -aliyun_nas_storage_class: "class-aliyun-nas-01" -aliyun_nas_controller_name: "aliyun-nas-controller-01" + # aliyun_nas 参数 + aliyun_nas: + enabled: "no" + server: "xxxxxxxxxxx.cn-hangzhou.nas.aliyuncs.com" + server_path: "/" + storage_class: "class-aliyun-nas-01" + controller_name: "aliyun-nas-controller-01" diff --git a/roles/cluster-storage/tasks/alicloud-nas.yml b/roles/cluster-storage/tasks/alicloud-nas.yml index c7c0178..2a1748d 100644 --- a/roles/cluster-storage/tasks/alicloud-nas.yml +++ b/roles/cluster-storage/tasks/alicloud-nas.yml @@ -4,7 +4,7 @@ - name: 生成alicloud-nas动态存储配置 template: src: alicloud-nas/alicloud-nas.yaml.j2 - dest: "{{ base_dir }}/manifests/storage/alicloud-nas/{{ aliyun_nas_controller_name }}.yaml" + dest: "{{ base_dir }}/manifests/storage/alicloud-nas/{{ storage.aliyun_nas.controller_name }}.yaml" - name: 复制alicloud-disk配置 copy: @@ -15,4 +15,4 @@ 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/{{ aliyun_nas_controller_name }}.yaml" + shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/alicloud-nas/{{ storage.aliyun_nas.controller_name }}.yaml" diff --git a/roles/cluster-storage/tasks/main.yml b/roles/cluster-storage/tasks/main.yml index afa8e15..effd68b 100644 --- a/roles/cluster-storage/tasks/main.yml +++ b/roles/cluster-storage/tasks/main.yml @@ -1,6 +1,6 @@ - include: nfs-client.yml - when: 'storage_nfs_enabled == "yes"' + when: 'storage.nfs.enabled == "yes"' - include: alicloud-nas.yml - when: 'storage_aliyun_nas_enabled == "yes"' + when: 'storage.aliyun_nas.enabled == "yes"' diff --git a/roles/cluster-storage/tasks/nfs-client.yml b/roles/cluster-storage/tasks/nfs-client.yml index ebc4d6e..07905d9 100644 --- a/roles/cluster-storage/tasks/nfs-client.yml +++ b/roles/cluster-storage/tasks/nfs-client.yml @@ -4,7 +4,7 @@ - name: 生成nfs-client动态存储配置 template: src: nfs/nfs-client-provisioner.yaml.j2 - dest: "{{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }}.yaml" + dest: "{{ base_dir }}/manifests/storage/nfs/{{ storage.nfs.provisioner_name }}.yaml" - name: 开始部署nfs-client动态存储 - shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/{{ nfs_provisioner_name }}.yaml" + shell: "{{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/storage/nfs/{{ storage.nfs.provisioner_name }}.yaml" diff --git a/roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 b/roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 index 7de60f8..4e0428a 100644 --- a/roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 +++ b/roles/cluster-storage/templates/alicloud-nas/alicloud-nas.yaml.j2 @@ -1,7 +1,7 @@ apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: - name: {{ aliyun_nas_storage_class }} + name: {{ storage.aliyun_nas.storage_class }} provisioner: alicloud/nas --- apiVersion: v1 @@ -26,7 +26,7 @@ roleRef: kind: Deployment apiVersion: apps/v1beta1 metadata: - name: {{ aliyun_nas_controller_name }} + name: {{ storage.aliyun_nas.controller_name }} namespace: kube-system spec: replicas: 1 @@ -35,7 +35,7 @@ spec: template: metadata: labels: - app: {{ aliyun_nas_controller_name }} + app: {{ storage.aliyun_nas.controller_name }} spec: serviceAccount: alicloud-nas-controller containers: @@ -48,11 +48,11 @@ spec: - name: PROVISIONER_NAME value: alicloud/nas - name: NFS_SERVER - value: {{ aliyun_nas_server }} + value: {{ storage.aliyun_nas.server }} - name: NFS_PATH - value: {{ aliyun_nas_server_path }} + value: {{ storage.aliyun_nas.server_path }} volumes: - name: nfs-client-root nfs: - server: {{ aliyun_nas_server }} - path: {{ aliyun_nas_server_path }} + server: {{ storage.aliyun_nas.server }} + path: {{ storage.aliyun_nas.server_path }} diff --git a/roles/cluster-storage/templates/dynamic-storageclass.yaml.j2 b/roles/cluster-storage/templates/dynamic-storageclass.yaml.j2 deleted file mode 100644 index a8a21cd..0000000 --- a/roles/cluster-storage/templates/dynamic-storageclass.yaml.j2 +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: storage.k8s.io/v1 -kind: StorageClass -metadata: - name: {{ storage_class_name }} -provisioner: prov diff --git a/roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 b/roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 index a2320df..1795b6c 100644 --- a/roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 +++ b/roles/cluster-storage/templates/nfs/nfs-client-provisioner.yaml.j2 @@ -41,7 +41,7 @@ roleRef: kind: Deployment apiVersion: apps/v1beta1 metadata: - name: {{ nfs_provisioner_name }} + name: {{ storage.nfs.provisioner_name }} namespace: kube-system spec: replicas: 1 @@ -49,11 +49,11 @@ spec: type: Recreate selector: matchLabels: - app: {{ nfs_provisioner_name }} + app: {{ storage.nfs.provisioner_name }} template: metadata: labels: - app: {{ nfs_provisioner_name }} + app: {{ storage.nfs.provisioner_name }} spec: serviceAccountName: nfs-client-provisioner containers: @@ -67,21 +67,21 @@ spec: env: - name: PROVISIONER_NAME # 此处供应者名字供storageclass调用 - value: {{ nfs_provisioner_name }} + value: {{ storage.nfs.provisioner_name }} - name: NFS_SERVER - value: {{ nfs_server }} + value: {{ storage.nfs.server }} - name: NFS_PATH - value: {{ nfs_server_path }} + value: {{ storage.nfs.server_path }} volumes: - name: nfs-client-root nfs: - server: {{ nfs_server }} - path: {{ nfs_server_path }} + server: {{ storage.nfs.server }} + path: {{ storage.nfs.server_path }} --- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: - name: {{ nfs_storage_class }} -provisioner: {{ nfs_provisioner_name }} + name: {{ storage.nfs.storage_class }} +provisioner: {{ storage.nfs.provisioner_name }}