K8s/Storage: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
Line 31: Line 31:
     path: /var/hostpath_pv/mariadb/mariadb-0
     path: /var/hostpath_pv/mariadb/mariadb-0
     type: DirectoryOrCreate
     type: DirectoryOrCreate
YML
</syntaxhighlight>
==Storage » Persistent Volume » Claim==
<syntaxhighlight lang="bash">
kubectl config get-contexts
kubectl get ns|grep mariadb
kubectl create namespace mariadb
</syntaxhighlight>
----
<syntaxhighlight lang="yaml" highlight="8,9,16,17" line>
cat << YML | kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app.kubernetes.io/name: mariadb
  name: mariadb-mariadb-0
  namespace: mariadb
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: hostpath
  volumeName: mariadb-mariadb-0
YML
YML
</syntaxhighlight>
</syntaxhighlight>

Revision as of 08:29, 11 June 2025

Storage » Class » Hostpath

cat <<'YML'| kubectl apply -f -
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: hostpath
provisioner: k8s.io/minikube-hostpath
reclaimPolicy: Retain
volumeBindingMode: Immediate
YML

Storage » Persistent Volume

cat <<'YML'| kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mariadb-mariadb-0
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: hostpath
  hostPath:
    path: /var/hostpath_pv/mariadb/mariadb-0
    type: DirectoryOrCreate
YML

Storage » Persistent Volume » Claim

kubectl config get-contexts
kubectl get ns|grep mariadb
kubectl create namespace mariadb

cat << YML | kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app.kubernetes.io/name: mariadb
  name: mariadb-mariadb-0
  namespace: mariadb
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: hostpath
  volumeName: mariadb-mariadb-0
YML

References