From 9823945312fbff57522fee33a5270a552cb48f3a Mon Sep 17 00:00:00 2001 From: guppy Date: Thu, 1 Jun 2023 16:01:43 +0200 Subject: [PATCH] exemples.yaml --- exemples.yaml | 10 +++ roles/nfs/tasks/main.yaml | 34 +++++++++ roles/nfs/templates/nfs-dep-sc.yaml.j2 | 47 ++++++++++++ roles/nfs/templates/nfs-pv-pvc.yaml.j2 | 26 +++++++ .../nfs-server-deployment-service.yaml.j2 | 76 +++++++++++++++++++ roles/nfs/vars/main.yml | 6 ++ 6 files changed, 199 insertions(+) create mode 100644 exemples.yaml create mode 100644 roles/nfs/tasks/main.yaml create mode 100644 roles/nfs/templates/nfs-dep-sc.yaml.j2 create mode 100644 roles/nfs/templates/nfs-pv-pvc.yaml.j2 create mode 100644 roles/nfs/templates/nfs-server-deployment-service.yaml.j2 create mode 100644 roles/nfs/vars/main.yml diff --git a/exemples.yaml b/exemples.yaml new file mode 100644 index 0000000..11752ee --- /dev/null +++ b/exemples.yaml @@ -0,0 +1,10 @@ +--- +- hosts: worker-node + name: "HostPath" + roles: + - role: hostpath +--- +- hosts: control-plane + name: "NFS" + roles: + - role: nfs diff --git a/roles/nfs/tasks/main.yaml b/roles/nfs/tasks/main.yaml new file mode 100644 index 0000000..7eb0aa1 --- /dev/null +++ b/roles/nfs/tasks/main.yaml @@ -0,0 +1,34 @@ +- name: install dep packages + become: yes + apt: + pkg: + - nfs-common + update_cache: yes + +- name: + file: + path: /tmp/nfs-server + state: directory + mode: '0755' + +- name: template every yaml.j2 files + template: + src: "{{item}}.j2" + dest: "/tmp/nfs-server/{{item}}" + with_items: + - nfs-pv-pvc.yaml + - nfs-server-deployment-service.yaml + - nfs-dep-sc.yaml + +- name: kubectl apply + shell: | + kubectl apply -f nfs-pv-pvc.yaml + # kubectl apply -f nfs-dep-sc.yaml + # kubectl apply -f nfs-server-deployment-service.yaml + register: output + args: + chdir: /tmp/nfs-server + +- name: Print return information from the previous task + debug: + var: output.stdout diff --git a/roles/nfs/templates/nfs-dep-sc.yaml.j2 b/roles/nfs/templates/nfs-dep-sc.yaml.j2 new file mode 100644 index 0000000..2a0d8df --- /dev/null +++ b/roles/nfs/templates/nfs-dep-sc.yaml.j2 @@ -0,0 +1,47 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: nfs-client +provisioner: external-nfs +parameters: + archiveOnDelete: "false" +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nfs-client-provisioner + labels: + app: nfs-client-provisioner + # replace with namespace where provisioner is deployed + namespace: default +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: nfs-client-provisioner + template: + metadata: + labels: + app: nfs-client-provisioner + spec: + serviceAccountName: nfs-client-provisioner + containers: + - name: nfs-client-provisioner + image: registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2 + volumeMounts: + - name: nfs-client-root + mountPath: /persistentvolumes + env: + - name: PROVISIONER_NAME + value: external-nfs + - name: NFS_SERVER + value: {{ nfsserver.ip }} + - name: NFS_PATH + value: {{ nfsserver.share }} + volumes: + - name: nfs-client-root + nfs: + server: {{ nfsserver.ip }} + path: {{ nfsserver.share }} diff --git a/roles/nfs/templates/nfs-pv-pvc.yaml.j2 b/roles/nfs/templates/nfs-pv-pvc.yaml.j2 new file mode 100644 index 0000000..75cba23 --- /dev/null +++ b/roles/nfs/templates/nfs-pv-pvc.yaml.j2 @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: nfs-pv +spec: + capacity: + storage: 100Mi + accessModes: + - ReadWriteMany + nfs: + path: "{{ nfsserver.share }}" + server: "{{ nfsserver.ip }}" +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nfs-pvc +spec: + accessModes: + - ReadWriteMany + storageClassName: "" + resources: + requests: + storage: 100Mi + volumeName: nfs-pv + diff --git a/roles/nfs/templates/nfs-server-deployment-service.yaml.j2 b/roles/nfs/templates/nfs-server-deployment-service.yaml.j2 new file mode 100644 index 0000000..86d530b --- /dev/null +++ b/roles/nfs/templates/nfs-server-deployment-service.yaml.j2 @@ -0,0 +1,76 @@ +apiVersion: v1 +kind: Service +metadata: + name: nfs-server +spec: + clusterIP: {{ nfsserver.ip }} + clusterIPs: + - {{ nfsserver.ip }} + ports: + - name: 111-tcp + port: 111 + protocol: TCP + targetPort: 111 + - name: 111-udp + port: 111 + protocol: UDP + targetPort: 111 + - name: 2049-tcp + port: 2049 + protocol: TCP + targetPort: 2049 + - name: 2049-udp + port: 2049 + protocol: UDP + targetPort: 2049 + - name: 32765-udp + port: 32765 + protocol: UDP + targetPort: 32765 + - name: 32765-tcp + port: 32765 + protocol: TCP + targetPort: 32765 + selector: + role: nfs-server + sessionAffinity: None + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nfs-server +spec: + replicas: 1 + selector: + matchLabels: + role: nfs-server + template: + metadata: + labels: + role: nfs-server + spec: + containers: + - name: nfs-server + image: erichough/nfs-server + env: + - name: NFS_EXPORT_0 + value: '/mnt/stage *(rw,sync,no_subtree_check,fsid=100)' + - name: NFS_LOG_LEVEL + value: DEBUG # doesn't debug client connections for some reason + securityContext: + privileged: true + volumeMounts: + - mountPath: /mnt/stage + name: nfs-stage-src + - mountPath: /lib/modules # mounting modules into container + name: lib-modules + readOnly: true # make sure it's readonly + + volumes: + - hostPath: # using hostpath to get modules from the host + path: /lib/modules + type: Directory + name: lib-modules + - name: nfs-stage-src + emptyDir: {} diff --git a/roles/nfs/vars/main.yml b/roles/nfs/vars/main.yml new file mode 100644 index 0000000..e4d9267 --- /dev/null +++ b/roles/nfs/vars/main.yml @@ -0,0 +1,6 @@ +--- +nfsserver: + ip: 192.168.1.159 + share: /share + #ip: 192.168.1.251 + #share: /media/2T