title | description |
---|---|
GKE Storage with GCP File Store - Default StorageClass |
Use GCP File Store for GKE Workloads with Default StorageClass |
- 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 - Default StorageClass
- Go to Kubernetes Engine -> standard-cluster-private-1 -> Details -> Features -> Filestore CSI driver
- Click on Checkbox Enable Filestore CSI Driver
- Click on SAVE CHANGES
# Verify Filestore CSI Daemonset in kube-system namespace
kubectl -n kube-system get ds | grep file
Observation:
1. You should find the Daemonset with name "filestore-node"
# Verify Filestore CSI Daemonset pods in kube-system namespace
kubectl -n kube-system get pods | grep file
Observation:
1. You should find the pods with name "filestore-node-*"
- After you enable the Filestore CSI driver, GKE automatically installs the following StorageClasses for provisioning Filestore instances:
- standard-rwx: using the Basic HDD Filestore service tier
- premium-rwx: using the Basic SSD Filestore service tier
- enterprise-rwx
- enterprise-multishare-rwx
# Default Storage Class created as part of FileStore CSI Enablement
kubectl get sc
Observation: Below four storage class will be created by default
standard-rwx
premium-rwx
enterprise-rwx
enterprise-multishare-rwx
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: gke-filestore-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: standard-rwx
resources:
requests:
storage: 1Ti
apiVersion: v1
kind: Pod
metadata:
name: filestore-writer-app
spec:
containers:
- name: app
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo GCP File Store used as PV in GKE $(date -u) >> /data/myapp1.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /data
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: gke-filestore-pvc
apiVersion: apps/v1
kind: Deployment
metadata: #Dictionary
name: myapp1-deployment
spec: # Dictionary
replicas: 2
selector:
matchLabels:
app: myapp1
template:
metadata: # Dictionary
name: myapp1-pod
labels: # Dictionary
app: myapp1 # Key value pairs
spec:
containers: # List
- name: myapp1-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: gke-filestore-pvc
apiVersion: v1
kind: Service
metadata:
name: myapp1-lb-service
spec:
type: LoadBalancer # ClusterIp, # NodePort
selector:
app: myapp1
ports:
- name: http
port: 80 # Service Port
targetPort: 80 # Container Port
- Go to Search -> FileStore -> ENABLE
# Deploy kube-manifests
kubectl apply -f 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
# 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
# Delete Kubernetes Objects
kubectl delete -f kube-manifests/
# Verify if FileStore Instance is deleted
Go to -> FileStore -> Instances