K8s/Storage: Difference between revisions
Jump to navigation
Jump to search
| (22 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
==Storage » Mount== | |||
<syntaxhighlight lang="bash"> | |||
cat <<'EXE'| sudo bash | |||
systemctl disable --now minikube.service | |||
systemctl status minikube.service | |||
EXE | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="ini" highlight="2"> | |||
cat <<'ENV'| sudo tee /etc/default/minikube >/dev/null | |||
MINIKUBE_OPTS="--cpus=12 --memory=27849 --addons=ingress,ingress-dns,dashboard,metrics-server --mount --mount-string=/var/minikube/pvc/:/var/hostpath_pv/ --apiserver-ips=10.20.40.3" | |||
MINIKUBE_CONF_ENV=/etc/default/minikube | |||
MINIKUBE_CONF_DIR="/home/minikube/.minikube" | |||
ENV | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="ini" highlight="21"> | |||
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 --mount-string=/var/minikube/pvc/:/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> | |||
---- | |||
<syntaxhighlight lang="bash"> | |||
cat <<'EXE'| sudo bash | |||
systemctl daemon-reload | |||
systemctl enable --now minikube.service | |||
systemctl status minikube.service | |||
journalctl -xeu minikube.service | |||
EXE | |||
</syntaxhighlight> | |||
==Storage » Class » Hostpath== | ==Storage » Class » Hostpath== | ||
<syntaxhighlight lang="yaml" highlight="6-8" line> | <syntaxhighlight lang="yaml" highlight="6-8" line> | ||
| Line 14: | Line 73: | ||
==Storage » Persistent Volume== | ==Storage » Persistent Volume== | ||
<syntaxhighlight lang="yaml" highlight="13-15" | {| | ||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
cat <<'EXE'| sudo bash | |||
mkdir -p /var/minikube/pvc/mariadb/data-mariadb-0/ | |||
chown -R 1001:1001 /var/minikube/pvc/mariadb/ | |||
EXE | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="yaml" highlight="13-15"> | |||
cat <<'YML'| kubectl apply -f - | cat <<'YML'| kubectl apply -f - | ||
--- | --- | ||
| Line 20: | Line 88: | ||
kind: PersistentVolume | kind: PersistentVolume | ||
metadata: | metadata: | ||
name: mariadb-mariadb-0 | name: mariadb-data-mariadb-0 | ||
spec: | spec: | ||
capacity: | capacity: | ||
| Line 29: | Line 97: | ||
storageClassName: hostpath | storageClassName: hostpath | ||
hostPath: | hostPath: | ||
path: /var/hostpath_pv/mariadb/mariadb-0 | path: /var/hostpath_pv/mariadb/data-mariadb-0 | ||
type: DirectoryOrCreate | type: DirectoryOrCreate | ||
YML | YML | ||
</syntaxhighlight> | </syntaxhighlight> | ||
---- | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl config get-contexts | kubectl config get-contexts | ||
kubectl get ns|grep mariadb | kubectl get ns |grep mariadb | ||
kubectl create namespace mariadb | kubectl create namespace mariadb | ||
</syntaxhighlight> | </syntaxhighlight> | ||
---- | ---- | ||
<syntaxhighlight lang="yaml" highlight="8,9,16,17" | <syntaxhighlight lang="yaml" highlight="8,9,16,17"> | ||
cat << YML | kubectl apply -f - | cat << YML | kubectl apply -f - | ||
--- | --- | ||
| Line 49: | Line 116: | ||
labels: | labels: | ||
app.kubernetes.io/name: mariadb | app.kubernetes.io/name: mariadb | ||
name: mariadb-0 | name: data-mariadb-0 | ||
namespace: mariadb | namespace: mariadb | ||
spec: | spec: | ||
| Line 58: | Line 125: | ||
storage: 10Gi | storage: 10Gi | ||
storageClassName: hostpath | storageClassName: hostpath | ||
volumeName: mariadb-mariadb-0 | volumeName: mariadb-data-mariadb-0 | ||
YML | |||
</syntaxhighlight> | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
cat <<'EXE'| sudo bash | |||
mkdir -p /var/minikube/pvc/postgresql/data-postgresql-0/ | |||
chown -R 1001:1001 /var/minikube/pvc/postgresql/ | |||
EXE | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="yaml" highlight="13-15" line> | |||
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 | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="bash"> | |||
kubectl config get-contexts | |||
kubectl get ns |grep postgresql | |||
kubectl create namespace postgresql | |||
</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: postgresql | |||
name: data-postgresql-0 | |||
namespace: postgresql | |||
spec: | |||
accessModes: | |||
- ReadWriteOnce | |||
resources: | |||
requests: | |||
storage: 10Gi | |||
storageClassName: hostpath | |||
volumeName: postgresql-data-postgresql-0 | |||
YML | YML | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |||
==Playground== | |||
{| | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n mariadb delete pvc --all | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n postgresql delete pvc --all | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl delete sc hostpath | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n mariadb delete pvc data-mariadb-0 | |||
kubectl delete pv mariadb-data-mariadb-0 | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n postgresql delete pvc data-postgresql-0 | |||
kubectl delete pv postgresql-data-postgresql-0 | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl delete namespace postgresql | |||
kubectl delete namespace mariadb | |||
</syntaxhighlight> | |||
|} | |||
==References== | ==References== | ||
| Line 66: | Line 229: | ||
|valign='top'| | |valign='top'| | ||
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]] | * [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]] | ||
* [[K8s/HAProxy/Ingress|K8s » HAProxy » Ingress]] | |||
* [[K8s/Apache/Ingress|K8s » Apache » Ingress]] | |||
* [[K8s/Nginx/Ingress|K8s » Nginx » Ingress]] | |||
* [[Minikube Ingress DNS|K8s » Ingress » DNS]] | |||
* [[K8s/Swiss Knife|K8s » Swiss Knife]] | * [[K8s/Swiss Knife|K8s » Swiss Knife]] | ||
* [[K8s/Ingress|K8s » Ingress]] | * [[K8s/Ingress|K8s » Ingress]] | ||
* [[K8s/Service|K8s » Service]] | * [[K8s/Service|K8s » Service]] | ||
* [[K8s/Secret|K8s » Secret]] | |||
* [[K8s/Run|K8s » Run]] | * [[K8s/Run|K8s » Run]] | ||
| Line 81: | Line 249: | ||
|valign='top'| | |valign='top'| | ||
* [[Helm/GitLab External|Helm » GitLab » External]] | * [[Helm/GitLab External|Helm » GitLab » External]] | ||
* [[Helm/PostgreSQL|Helm » PostgreSQL]] | * [[Helm/PostgreSQL/PV|Helm » PostgreSQL » PV]] | ||
* [[Helm/MariaDB|Helm » MariaDB]] | * [[Helm/MariaDB/PV|Helm » MariaDB » PV]] | ||
* [[Minikube MetalLB|Helm » MetalLB]] | |||
* [[Helm/GitLab|Helm » GitLab]] | * [[Helm/GitLab|Helm » GitLab]] | ||
* [[Helm/Kafka|Helm » Kafka]] | |||
* [[Helm/Redis|Helm » Redis]] | * [[Helm/Redis|Helm » Redis]] | ||
Latest revision as of 06:53, 10 July 2025
Storage » Mount
cat <<'EXE'| sudo bash
systemctl disable --now minikube.service
systemctl status minikube.service
EXE
cat <<'ENV'| sudo tee /etc/default/minikube >/dev/null
MINIKUBE_OPTS="--cpus=12 --memory=27849 --addons=ingress,ingress-dns,dashboard,metrics-server --mount --mount-string=/var/minikube/pvc/:/var/hostpath_pv/ --apiserver-ips=10.20.40.3"
MINIKUBE_CONF_ENV=/etc/default/minikube
MINIKUBE_CONF_DIR="/home/minikube/.minikube"
ENV
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 --mount-string=/var/minikube/pvc/:/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
cat <<'EXE'| sudo bash
systemctl daemon-reload
systemctl enable --now minikube.service
systemctl status minikube.service
journalctl -xeu minikube.service
EXE
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 <<'EXE'| sudo bash
mkdir -p /var/minikube/pvc/mariadb/data-mariadb-0/
chown -R 1001:1001 /var/minikube/pvc/mariadb/
EXE
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 <<'EXE'| sudo bash
mkdir -p /var/minikube/pvc/postgresql/data-postgresql-0/
chown -R 1001:1001 /var/minikube/pvc/postgresql/
EXE
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
|
kubectl delete namespace postgresql
kubectl delete namespace mariadb
|
References
|
| ||
|
| ||