title | description |
---|---|
GKE Storage with GCP File Store - Backup and Restore |
Use GCP File Store for GKE Workloads - Implement Backup and Restore |
- Verify if GKE Cluster is created
- Verify if kubeconfig for kubectl is configured in your local terminal
# Configure kubeconfig for kubectl
gcloud container clusters get-credentials <CLUSTER-NAME> --region <REGION> --project <PROJECT>
# Replace Values CLUSTER-NAME, ZONE, PROJECT
gcloud container clusters get-credentials standard-cluster-private-1 --region us-central1 --project kdaida123
- GKE Storage with GCP File Store
- Implement Backups is
VolumeSnapshotClass
andVolumeSnapshot
- Implement Restore of FileStore in myapp2 Application and Verify
- Project Folder: 01-myapp1-kube-manifests
- YAML files are same as first FileStore Demo
- 01-filestore-pvc.yaml
- 02-write-to-filestore-pod.yaml
- 03-myapp1-deployment.yaml
- 04-loadBalancer-service.yaml
# Deploy 01-myapp1-kube-manifests
kubectl apply -f 01-myapp1-kube-manifests
# List Storage Class
kubectl get sc
# List PVC
kubectl get pvc
# List PV
kubectl get pv
# List Pods
kubectl get pods
- Go to FileStore -> Instances
- Click on Instance ID: pvc-27cd5c27-0ed0-48d1-bc5f-925adfb8495f
- Note: Instance ID dynamically generated, it can be different in your case starting with pvc-*
# FileStore write app - Connect to Kubernetes Pod
kubectl exec --stdin --tty <POD-NAME> -- /bin/sh
kubectl exec --stdin --tty filestore-writer-app -- /bin/sh
cd /data
ls
tail -f myapp1.txt
exit
# List Pods
kubectl get pods
# myapp1 POD1 - Connect to Kubernetes Pod
kubectl exec --stdin --tty <POD-NAME> -- /bin/sh
kubectl exec --stdin --tty myapp1-deployment-5d469f6478-2kp97 -- /bin/sh
cd /usr/share/nginx/html/filestore
ls
tail -f myapp1.txt
exit
# myapp1 POD2 - Connect to Kubernetes Pod
kubectl exec --stdin --tty <POD-NAME> -- /bin/sh
kubectl exec --stdin --tty myapp1-deployment-5d469f6478-2kp97 -- /bin/sh
cd /usr/share/nginx/html/filestore
ls
tail -f myapp1.txt
exit
# List Services
kubectl get svc
# myapp1 - Access Application
http://<EXTERNAL-IP-OF-GET-SERVICE-OUTPUT>/filestore/myapp1.txt
http://35.232.145.61/filestore/myapp1.txt
curl http://35.232.145.61/filestore/myapp1.txt
- Project Folder: 02-volume-backup-kube-manifests
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: csi-gcp-filestore-backup-snap-class
driver: filestore.csi.storage.gke.io
parameters:
type: backup
deletionPolicy: Delete
- Project Folder: 02-volume-backup-kube-manifests
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: myapp1-volume-snapshot
spec:
volumeSnapshotClassName: csi-gcp-filestore-backup-snap-class
source:
persistentVolumeClaimName: gke-filestore-pvc
# Deploy 02-volume-backup-kube-manifests
kubectl apply -f 02-volume-backup-kube-manifests
# List VolumeSnapshotClass
kubectl get volumesnapshotclass
# Describe VolumeSnapshotClass
kubectl describe volumesnapshotclass csi-gcp-filestore-backup-snap-class
# List VolumeSnapshot
kubectl get volumesnapshot
# Describe VolumeSnapshot
kubectl describe volumesnapshot myapp1-volume-snapshot
- Go to FileStore -> Backups
- Observation: You should find the Backup with name
snapshot-<SOME-ID>
(Example: snapshot-b4f24bd7-649b-45bb-8a0a-2b09d5b0e631)
- Project Folder: 03-volume-restore-myapp2-kube-manifests
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: restored-filestore-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: standard-rwx
resources:
requests:
storage: 1Ti
dataSource:
kind: VolumeSnapshot
name: myapp1-volume-snapshot
apiGroup: snapshot.storage.k8s.io
- Project Folder: 03-volume-restore-myapp2-kube-manifests
apiVersion: apps/v1
kind: Deployment
metadata: #Dictionary
name: myapp2-deployment
spec: # Dictionary
replicas: 2
selector:
matchLabels:
app: myapp2
template:
metadata: # Dictionary
name: myapp2-pod
labels: # Dictionary
app: myapp2 # Key value pairs
spec:
containers: # List
- name: myapp2-container
image: stacksimplify/kubenginx:1.0.0
ports:
- containerPort: 80
volumeMounts:
- name: persistent-storage
mountPath: /usr/share/nginx/html/filestore
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: restored-filestore-pvc
- Project Folder: 03-volume-restore-myapp2-kube-manifests
apiVersion: v1
kind: Service
metadata:
name: myapp2-lb-service
spec:
type: LoadBalancer # ClusterIp, # NodePort
selector:
app: myapp2
ports:
- name: http
port: 80 # Service Port
targetPort: 80 # Container Port
# Deploy 03-volume-restore-myapp2-kube-manifests
kubectl apply -f 03-volume-restore-myapp2-kube-manifests
# List Storage Class
kubectl get sc
# List PVC
kubectl get pvc
# List PV
kubectl get pv
# List Pods
kubectl get pods
# Verify if new FileStore Instance is Created
Go to -> FileStore -> Instances
# List Pods
kubectl get pods
# myapp1 POD1 - Connect to Kubernetes Pod
kubectl exec --stdin --tty <POD-NAME> -- /bin/sh
kubectl exec --stdin --tty myapp2-deployment-6dccd6557-9x6dn -- /bin/sh
cd /usr/share/nginx/html/filestore
ls
tail -f myapp1.txt
exit
# myapp1 POD2 - Connect to Kubernetes Pod
kubectl exec --stdin --tty <POD-NAME> -- /bin/sh
kubectl exec --stdin --tty myapp2-deployment-6dccd6557-mbbjm -- /bin/sh
cd /usr/share/nginx/html/filestore
ls
tail -f myapp1.txt
exit
# List Services
kubectl get svc
# myapp1 - Access Application
http://<MYAPP1-EXTERNAL-IP-OF-GET-SERVICE-OUTPUT>/filestore/myapp1.txt
http://35.232.145.61/filestore/myapp1.txt
# myapp2 - Access Application
http://<MYAPP2-EXTERNAL-IP-OF-GET-SERVICE-OUTPUT>/filestore/myapp1.txt
http://34.71.145.41/filestore/myapp1.txt
OBSERVATION:
1. For MyApp1, writer app is writing to FileStore so we get latest timestamp lines (many lines and file growing)
2. For MyApp2, we have restored it from backup, which means the number of lines present in file at the time of snapshot will be only displayed.
3. KEY here is we are able to successfully use the filestore backup for our Kubernetes Workloads
# Delete Kubernetes Objects
kubectl delete -f 01-myapp1-kube-manifests -f 02-volume-backup-kube-manifests -f 03-volume-restore-myapp2-kube-manifests
# Verify if two FileStore Instances are deleted
Go to -> FileStore -> Instances
# Verify if FileStore Backup is deleted
Go to -> FileStore -> Backups