K8s/Storage: Difference between revisions
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
==Storage » Mount== | |||
<syntaxhighlight lang="ini" highlight="19-22" line> | |||
cat <<'INI'| sudo tee /etc/systemd/system/minikube.service >/dev/null | |||
[Unit] | |||
Description=Minikube Cluster | |||
Documentation=https://minikube.sigs.k8s.io/docs/ | |||
After=network-online.target containerd.service docker.service | |||
Requires=network-online.target containerd.service docker.service | |||
Wants=network-online.target docker.service | |||
AssertFileIsExecutable=/var/minikube/bin/minikube | |||
[Service] | |||
Type=forking | |||
User=minikube | |||
Group=minikube | |||
RemainAfterExit=yes | |||
ProtectProc=invisible | |||
StandardOutput=journal | |||
WorkingDirectory=/var/minikube | |||
EnvironmentFile=-/etc/default/minikube | |||
ExecStartPre=/bin/bash -c "if [ -z \"${MINIKUBE_OPTS}\" ]; then echo \"Variable MINIKUBE_OPTS not set in /etc/default/minikube\"; errors_exit; fi" | |||
ExecStart=/var/minikube/bin/minikube start --cpus=12 --memory=27849 --addons=ingress,ingress-dns,dashboard,metrics-server --mount=true --mount-string=/var/minikube/pvc/standard/:/var/hostpath-provisioner/ --mount-string=/var/minikube/pvc/hostpath/:/var/hostpath_pv/ --apiserver-ips=10.20.40.3 | |||
ExecStop=/var/minikube/bin/minikube stop | |||
Restart=always | |||
SendSIGKILL=no | |||
TasksMax=infinity | |||
TimeoutStopSec=infinity | |||
[Install] | |||
WantedBy=multi-user.target | |||
INI | |||
</syntaxhighlight> | |||
==Storage » Class » Hostpath== | ==Storage » Class » Hostpath== | ||
<syntaxhighlight lang="yaml" highlight="6-8" line> | <syntaxhighlight lang="yaml" highlight="6-8" line> | ||
Revision as of 03:09, 12 June 2025
Storage » Mount
cat <<'INI'| sudo tee /etc/systemd/system/minikube.service >/dev/null
[Unit]
Description=Minikube Cluster
Documentation=https://minikube.sigs.k8s.io/docs/
After=network-online.target containerd.service docker.service
Requires=network-online.target containerd.service docker.service
Wants=network-online.target docker.service
AssertFileIsExecutable=/var/minikube/bin/minikube
[Service]
Type=forking
User=minikube
Group=minikube
RemainAfterExit=yes
ProtectProc=invisible
StandardOutput=journal
WorkingDirectory=/var/minikube
EnvironmentFile=-/etc/default/minikube
ExecStartPre=/bin/bash -c "if [ -z \"${MINIKUBE_OPTS}\" ]; then echo \"Variable MINIKUBE_OPTS not set in /etc/default/minikube\"; errors_exit; fi"
ExecStart=/var/minikube/bin/minikube start --cpus=12 --memory=27849 --addons=ingress,ingress-dns,dashboard,metrics-server --mount=true --mount-string=/var/minikube/pvc/standard/:/var/hostpath-provisioner/ --mount-string=/var/minikube/pvc/hostpath/:/var/hostpath_pv/ --apiserver-ips=10.20.40.3
ExecStop=/var/minikube/bin/minikube stop
Restart=always
SendSIGKILL=no
TasksMax=infinity
TimeoutStopSec=infinity
[Install]
WantedBy=multi-user.target
INI
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
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
|
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
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
|
Playground
kubectl -n mariadb delete pvc --all
|
kubectl -n postgresql delete pvc --all
|
kubectl delete sc hostpath
|
|
| ||
kubectl -n mariadb delete pvc data-mariadb-0
kubectl delete pv mariadb-data-mariadb-0
|
kubectl -n postgresql delete pvc data-postgresql-0
kubectl delete pv postgresql-data-postgresql-0
|
|
References
|
| ||
|
| ||