kubernetes_nfs_dynamic
Differences
This shows you the differences between two versions of the page.
| kubernetes_nfs_dynamic [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadm | kubernetes_nfs_dynamic [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Volume dinâmico com NFS ====== | ||
| - | Passo anterior: [[kubernetes_install_debian|Instalação Kubernetes]] | ||
| - | <file bash> | ||
| - | $ sudo apt install nfs-kernel-server nfs-common | ||
| - | </ | ||
| - | ===== Volume a ser exportado ===== | ||
| - | <file bash> | ||
| - | $ MOUNT_POINT=/ | ||
| - | $ DISK_DEVICE=/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ echo -e " | ||
| - | |||
| - | Bem-vindo ao fdisk (util-linux 2.36.1). | ||
| - | As alterações permanecerão apenas na memória, até que você decida gravá-las. | ||
| - | Tenha cuidado antes de usar o comando de gravação. | ||
| - | |||
| - | A unidade não contém uma tabela de partição conhecida. | ||
| - | Criado um novo rótulo de disco DOS com o identificador de disco 0x7e42ac59. | ||
| - | |||
| - | Comando (m para ajuda): Tipo da partição | ||
| - | | ||
| - | | ||
| - | Selecione (padrão p): Número da partição (1-4, padrão 1): Primeiro setor (2048-268435455, | ||
| - | Criada uma nova partição 1 do tipo " | ||
| - | |||
| - | Comando (m para ajuda): A tabela de partição foi alterada. | ||
| - | Chamando ioctl() para reler tabela de partição. | ||
| - | Sincronizando discos. | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo mkfs.ext4 ${DISK_DEVICE}1 | ||
| - | mke2fs 1.46.2 (28-Feb-2021) | ||
| - | Creating filesystem with 33554176 4k blocks and 8388608 inodes | ||
| - | Filesystem UUID: 348ddaa1-0b59-4def-81bc-2e737460013c | ||
| - | Superblock backups stored on blocks: | ||
| - | 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, | ||
| - | 4096000, 7962624, 11239424, 20480000, 23887872 | ||
| - | |||
| - | Allocating group tables: done | ||
| - | Writing inode tables: done | ||
| - | Creating journal (131072 blocks): done | ||
| - | Writing superblocks and filesystem accounting information: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ UUID=`sudo blkid -o export ${DISK_DEVICE}1 | grep UUID | grep -v PARTUUID` | ||
| - | $ sudo mkdir ${MOUNT_POINT} | ||
| - | $ sudo cp -p / | ||
| - | $ echo " | ||
| - | UUID=348ddaa1-0b59-4def-81bc-2e737460013c | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo mount ${MOUNT_POINT} | ||
| - | gean@nfs-kube: | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo mkdir / | ||
| - | $ sudo chown nobody: | ||
| - | $ sudo chmod 0777 / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ echo '/ | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo systemctl restart nfs-kernel-server | ||
| - | $ sudo exportfs -s | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo exportfs -arv | ||
| - | exporting 177.75.176.32/ | ||
| - | </ | ||
| - | |||
| - | ===== Clientes onde os volumes serão montados - Kube nodes ===== | ||
| - | <file bash> | ||
| - | $ sudo apt install nfs-common | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo showmount -e 177.75.176.43 | ||
| - | Export list for 177.75.176.43: | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | ===== Control Plane ===== | ||
| - | <file bash> | ||
| - | $ git clone https:// | ||
| - | Cloning into ' | ||
| - | remote: Enumerating objects: 7248, done. | ||
| - | remote: Counting objects: 100% (4/4), done. | ||
| - | remote: Compressing objects: 100% (4/4), done. | ||
| - | remote: Total 7248 (delta 0), reused 1 (delta 0), pack-reused 7244 | ||
| - | Receiving objects: 100% (7248/ | ||
| - | Resolving deltas: 100% (3900/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ cd nfs-subdir-external-provisioner/ | ||
| - | $ ls | ||
| - | class.yaml | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl create ns nfs-system | ||
| - | namespace/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ vim rbac.yaml | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl apply -f rbac.yaml | ||
| - | serviceaccount/ | ||
| - | clusterrole.rbac.authorization.k8s.io/ | ||
| - | clusterrolebinding.rbac.authorization.k8s.io/ | ||
| - | role.rbac.authorization.k8s.io/ | ||
| - | rolebinding.rbac.authorization.k8s.io/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ vim class.yaml | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl apply -f class.yaml | ||
| - | storageclass.storage.k8s.io/ | ||
| - | </ | ||
| - | |||
| - | <file yaml deployment.yaml> | ||
| - | --- | ||
| - | apiVersion: apps/v1 | ||
| - | kind: Deployment | ||
| - | metadata: | ||
| - | name: nfs-client-provisioner | ||
| - | labels: | ||
| - | app: nfs-client-provisioner | ||
| - | # replace with namespace where provisioner is deployed | ||
| - | namespace: nfs-system | ||
| - | spec: | ||
| - | replicas: 1 | ||
| - | strategy: | ||
| - | type: Recreate | ||
| - | selector: | ||
| - | matchLabels: | ||
| - | app: nfs-client-provisioner | ||
| - | template: | ||
| - | metadata: | ||
| - | labels: | ||
| - | app: nfs-client-provisioner | ||
| - | spec: | ||
| - | serviceAccountName: | ||
| - | containers: | ||
| - | - name: nfs-client-provisioner | ||
| - | image: k8s.gcr.io/ | ||
| - | volumeMounts: | ||
| - | - name: nfs-client-root | ||
| - | mountPath: / | ||
| - | env: | ||
| - | - name: PROVISIONER_NAME | ||
| - | value: k8s-sigs.io/ | ||
| - | - name: NFS_SERVER | ||
| - | value: 177.75.176.43 | ||
| - | - name: NFS_PATH | ||
| - | value: / | ||
| - | volumes: | ||
| - | - name: nfs-client-root | ||
| - | nfs: | ||
| - | server: 177.75.176.43 | ||
| - | path: / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl apply -f deployment.yaml | ||
| - | deployment.apps/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl get all -n nfs-system | ||
| - | NAME READY | ||
| - | pod/ | ||
| - | |||
| - | NAME | ||
| - | deployment.apps/ | ||
| - | |||
| - | NAME DESIRED | ||
| - | replicaset.apps/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl describe pod nfs-client-provisioner-8686cbd686-dbrgn -n nfs-system | ||
| - | Name: | ||
| - | Namespace: | ||
| - | Priority: | ||
| - | Node: | ||
| - | Start Time: Thu, 12 May 2022 18:16:25 -0300 | ||
| - | Labels: | ||
| - | pod-template-hash=8686cbd686 | ||
| - | Annotations: | ||
| - | cni.projectcalico.org/ | ||
| - | cni.projectcalico.org/ | ||
| - | Status: | ||
| - | IP: | ||
| - | IPs: | ||
| - | IP: | ||
| - | IP: | ||
| - | Controlled By: ReplicaSet/ | ||
| - | Containers: | ||
| - | nfs-client-provisioner: | ||
| - | Container ID: | ||
| - | Image: | ||
| - | Image ID: | ||
| - | Port: < | ||
| - | Host Port: < | ||
| - | State: | ||
| - | Started: | ||
| - | Ready: | ||
| - | Restart Count: | ||
| - | Environment: | ||
| - | PROVISIONER_NAME: | ||
| - | NFS_SERVER: | ||
| - | NFS_PATH: | ||
| - | Mounts: | ||
| - | / | ||
| - | / | ||
| - | Conditions: | ||
| - | Type Status | ||
| - | Initialized | ||
| - | Ready True | ||
| - | ContainersReady | ||
| - | PodScheduled | ||
| - | Volumes: | ||
| - | nfs-client-root: | ||
| - | Type: NFS (an NFS mount that lasts the lifetime of a pod) | ||
| - | Server: | ||
| - | Path: / | ||
| - | ReadOnly: | ||
| - | kube-api-access-mwt8r: | ||
| - | Type: Projected (a volume that contains injected data from multiple sources) | ||
| - | TokenExpirationSeconds: | ||
| - | ConfigMapName: | ||
| - | ConfigMapOptional: | ||
| - | DownwardAPI: | ||
| - | QoS Class: | ||
| - | Node-Selectors: | ||
| - | Tolerations: | ||
| - | | ||
| - | Events: | ||
| - | Type Reason | ||
| - | ---- ------ | ||
| - | Normal | ||
| - | Normal | ||
| - | Normal | ||
| - | Normal | ||
| - | Normal | ||
| - | </ | ||
| - | |||
| - | ===== Teste ===== | ||
| - | <file yaml test-claim.yaml> | ||
| - | --- | ||
| - | kind: PersistentVolumeClaim | ||
| - | apiVersion: v1 | ||
| - | metadata: | ||
| - | name: test-claim | ||
| - | spec: | ||
| - | storageClassName: | ||
| - | accessModes: | ||
| - | - ReadWriteMany | ||
| - | resources: | ||
| - | requests: | ||
| - | storage: 1Mi | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl apply -f test-claim.yaml | ||
| - | persistentvolumeclaim/ | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl get pv,pvc | ||
| - | NAME CAPACITY | ||
| - | persistentvolume/ | ||
| - | |||
| - | NAME | ||
| - | persistentvolumeclaim/ | ||
| - | </ | ||
| - | |||
| - | <file yaml test-pod.yaml> | ||
| - | --- | ||
| - | kind: Pod | ||
| - | apiVersion: v1 | ||
| - | metadata: | ||
| - | name: test-pod | ||
| - | spec: | ||
| - | containers: | ||
| - | - name: test-pod | ||
| - | image: busybox: | ||
| - | command: | ||
| - | - "/ | ||
| - | args: | ||
| - | - " | ||
| - | - "touch / | ||
| - | volumeMounts: | ||
| - | - name: nfs-pvc | ||
| - | mountPath: "/ | ||
| - | restartPolicy: | ||
| - | volumes: | ||
| - | - name: nfs-pvc | ||
| - | persistentVolumeClaim: | ||
| - | claimName: test-claim | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl apply -f test-pod.yaml | ||
| - | pod/ | ||
| - | </ | ||
| - | |||
| - | **No servidor NFS:** | ||
| - | <file bash> | ||
| - | $ ls / | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl delete -f test-pod.yaml -f test-claim.yaml | ||
| - | pod " | ||
| - | persistentvolumeclaim " | ||
| - | </ | ||
kubernetes_nfs_dynamic.1753560544.txt.gz · Last modified: by wikiadm
