GKE su AWS versione 1.6 e successive supportano AWS Elastic File System (EFS) tramite EFS CSI Driver. Questo argomento spiega come montare un file system EFS esistente come PersistentVolume nei cluster utente.
Prima di iniziare
Per eseguire i passaggi descritti in questo argomento, devi disporre di quanto segue:
- Un file system EFS esistente nello stesso VPC AWS dell'installazione di GKE su AWS.
- Almeno un target di montaggio EFS nello stesso VPC AWS dell'installazione GKE su AWS.
- Tutte le destinazioni di montaggio EFS devono appartenere a quanto segue:
- Le subnet private per l'installazione di GKE su AWS. Per impostazione predefinita, GKE su AWS crea subnet denominate
gke-CLUSTER_ID-private-AWS_ZONE
, dove CLUSTER_ID è l'ID del cluster utente e AWS_ZONE è la zona di disponibilità AWS. - Il
gruppo di sicurezza del node pool.
Per impostazione predefinita, GKE su AWS crea node pool denominati
gke-CLUSTER_ID-nodepool
, dove CLUSTER_ID è l'ID del cluster utente.
- Le subnet private per l'installazione di GKE su AWS. Per impostazione predefinita, GKE su AWS crea subnet denominate
- Dalla directory
anthos-aws
, utilizzaanthos-gke
per passare al contesto del cluster utente. Sostituisci CLUSTER_NAME con il nome del cluster utente.cd anthos-aws env HTTPS_PROXY=http://localhost:8118 \ anthos-gke aws clusters get-credentials CLUSTER_NAME
Utilizzo di un PersistentVolume EFS
Per utilizzare un file system EFS come PersistentVolume con i cluster utente, devi prima creare un PersistentVolume e poi creare un PersistentVolumeClaim a cui fai riferimento nel tuo workload.
Creazione di un PersistentVolume
Per creare un PersistentVolume con il driver CSI EFS, segui questi passaggi.
Dalla directory
anthos-aws
, utilizzaanthos-gke
per passare al contesto del cluster utente. Sostituisci CLUSTER_NAME con il nome del cluster utente.cd anthos-aws env HTTPS_PROXY=http://localhost:8118 \ anthos-gke aws clusters get-credentials CLUSTER_NAME
La configurazione di PersistentVolume che utilizzi dipende dal fatto che tu ti connetta direttamente a Elastic File System o tramite un punto di accesso. Seleziona se ti connetti a Elastic File System direttamente o tramite un punto di accesso.
Connettersi direttamente
Copia il seguente manifest YAML in un file denominato
efs-volume.yaml
. Il manifest fa riferimento alla classe di archiviazione EFS che hai creato in precedenza.apiVersion: v1 kind: PersistentVolume metadata: name: VOLUME_NAME spec: capacity: # Note: storage capacity is not used by the EFS CSI driver. # It is required by the PersistentVolume spec. storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain storageClassName: "" # storageClassName is not required, see note in the following section. claimRef: name: CLAIM_NAME namespace: default csi: driver: efs.csi.aws.com volumeHandle: EFS_FILE_SYSTEM_ID
Sostituisci quanto segue:
- VOLUME_NAME con un nome per il volume permanente.
- CLAIM_NAME con il nome che vuoi utilizzare per PersistentVolumeClaim.
- EFS_FILE_SYSTEM_ID con l'ID del file system EFS. Ad esempio,
fs-12345678a
.
Punto di accesso
Copia il seguente manifest YAML in un file denominato
efs-volume.yaml
. Il manifest fa riferimento alla classe di archiviazione EFS che hai creato in precedenza.apiVersion: v1 kind: PersistentVolume metadata: name: VOLUME_NAME spec: capacity: # Note: storage capacity is not used by the EFS CSI driver. # It is required by the PersistentVolume spec. storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain storageClassName: "" # storageClassName is not required, see note in the following section. claimRef: name: CLAIM_NAME namespace: default csi: driver: efs.csi.aws.com volumeHandle: EFS_FILE_SYSTEM_ID::ACCESS_POINT_ID
Sostituisci quanto segue:
- VOLUME_NAME con un nome per il volume permanente.
- CLAIM_NAME con il nome che vuoi utilizzare per PersistentVolumeClaim.
- EFS_FILE_SYSTEM_ID con l'ID del file system EFS. Ad esempio,
fs-12345678a
. - ACCESS_POINT_ID: l'ID del tuo punto di accesso. Ad esempio,
fsap-1234567890abcde
.
Applica il file YAML al cluster utente.
env HTTPS_PROXY=http://localhost:8118 \ kubectl apply -f efs-volume.yaml
L'output conferma la creazione di PersistentVolume.
persistentvolume/VOLUME_NAME created
Creazione di un PersistentVolumeClaim
Per utilizzare il file system EFS con i tuoi carichi di lavoro, crea un oggetto PersistentVolumeClaim.
Per creare PersistentVolumeClaim, copia il seguente manifest YAML in un file denominato
efs-claim.yaml
.apiVersion: v1 kind: PersistentVolumeClaim metadata: name: CLAIM_NAME spec: accessModes: - ReadWriteMany storageClassName: "" resources: requests: storage: 5Gi
Sostituisci CLAIM_NAME con un nome per PersistentVolumeClaim. Ad esempio,
efs-claim1
.Applica il file YAML al cluster utente.
env HTTPS_PROXY=http://localhost:8118 \ kubectl apply -f efs-claim.yaml
L'output conferma la creazione di PersistentVolumeClaim.
persistentvolumeclaim/CLAIM_NAME created
Crea un oggetto StatefulSet
Dopo aver creato un PersistentVolumeClaim, puoi utilizzarlo in un workload.
I passaggi descritti in questa sezione creano un StatefulSet di esempio con il file system EFS montato. Puoi utilizzare un PersistentVolumeClaim anche con altri tipi di workload, come pod e deployment, facendo riferimento alla richiesta in spec.volumes
.
Per creare uno StatefulSet che monta il file system EFS a cui fa riferimento la tua PersistentVolumeClaim, esegui questi passaggi.
Copia il seguente manifest YAML in un file denominato
efs-statefulset.yaml
. Questo manifest di esempio avvia un container Ubuntu Linux che monta il file system EFS in/efs-data
. Il container scrive ogni cinque secondi in un file del file system EFS denominatoout.txt
.apiVersion: apps/v1 kind: StatefulSet metadata: name: efs-shell spec: selector: matchLabels: app: test-efs serviceName: efs-app replicas: 1 template: metadata: labels: app: test-efs spec: terminationGracePeriodSeconds: 10 containers: - name: linux image: ubuntu:bionic command: ["/bin/sh"] args: ["-c", "while true; do echo $(date -u) >> /efs-data/out.txt; sleep 5; done"] volumeMounts: - name: efs-volume mountPath: /efs-data volumes: - name: efs-volume persistentVolumeClaim: claimName: CLAIM_NAME
Sostituisci quanto segue:
- CLAIM_NAME con il nome di PersistentVolumeClaim
che hai specificato in precedenza. Ad esempio,
efs-claim1
.
- CLAIM_NAME con il nome di PersistentVolumeClaim
che hai specificato in precedenza. Ad esempio,
Applica il file YAML al cluster utente.
env HTTPS_PROXY=http://localhost:8118 \ kubectl apply -f efs-statefulset.yaml
L'output conferma la creazione di StatefulSet.
statefulset.apps/efs-shell created
Il StatefulSet potrebbe richiedere diversi minuti per scaricare l'immagine container e avviarsi.
Verifica che il pod di StatefulSet sia nello stato
Running
conkubectl get pods
.env HTTPS_PROXY=http://localhost:8118 \ kubectl get pods -l app=test-efs
L'output include il nome del pod e il relativo stato. Nella risposta seguente, il nome del pod è
efs-shell-0
.NAME READY STATUS RESTARTS AGE efs-shell-0 1/1 Running 0 1m
Quando il pod è in stato Running, utilizza
kubectl exec
per connetterti al pod che ospita lo StatefulSet.env HTTPS_PROXY=http://localhost:8118 \ kubectl exec -it efs-shell-0 -- bash
Il comando
kubectl
avvia una shell sul pod.Per verificare che il file system EFS sia montato, controlla i contenuti del file
out.txt
con il comandotail
.tail /efs-data/out.txt
L'output contiene orari recenti in formato UTC.
Disconnettiti dal pod con il comando
exit
.exit
La shell torna alla tua macchina locale.
Per rimuovere lo StatefulSet, utilizza
kubectl delete
.env HTTPS_PROXY=http://localhost:8118 \ kubectl delete -f efs-statefulset.yaml
Pulizia
Per rimuovere le risorse create nelle sezioni precedenti, esegui i seguenti comandi:
env HTTPS_PROXY=http://localhost:8118 \
kubectl delete -f efs-statefulset.yaml
env HTTPS_PROXY=http://localhost:8118 \
kubectl delete -f efs-claim.yaml
env HTTPS_PROXY=http://localhost:8118 \
kubectl delete -f efs-volume.yaml
Passaggi successivi
- Scopri altri modi per utilizzare i volumi EFS negli
esempi di
aws-efs-csi-driver
.