K8s/Storage

From Chorke Wiki
Jump to navigation Jump to search

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-data-mariadb-0
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: hostpath
  hostPath:
    path: /var/hostpath_pv/mariadb/data-mariadb-0
    type: DirectoryOrCreate
YML
cat <<'YML'| kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgresql-data-postgresql-0
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: hostpath
  hostPath:
    path: /var/hostpath_pv/postgresql/data-postgresql-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: data-mariadb-0
  namespace: mariadb
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: hostpath
  volumeName: mariadb-data-mariadb-0
YML
kubectl config get-contexts
kubectl get    ns  |grep postgresql
kubectl create namespace postgresql

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

References