In this sample, we need to create four Persistent Volumes (PV) and Persistent Volume Claims (PVC) to store data for MySQL, Prometheus server, Prometheus Alertmanager, and Grafana. See the following YAML files for the four PVs/PVCs:
- PV and PVC for MYSQL server
- PV and PVC for Prometheus server
- PV and PVC for Prometheus Alertmanager
- PV and PVC for Grafana server
Note: To simplify the configuration, we use
hostPath
PV that works only in a single-node Kubernetes cluster; therefore, it's for demonstration purposes only. In a production environment, you would need to use a more sophisticated PV type like NFS, iSCSI. For detailed information, see the Kubernetes Types of Persistent Volumes document.
To simplify the configuration and management, the four PVs will share the same root path. Prepare a host folder as the root path of the PVs.
Create a new folder in the host machine and set the PV_ROOT
env.
mkdir <someDIR>
export PV_ROOT=<someDIR>
Then use the following commands to auto-update the path values in the PV and PVC YAML files:
sed -i 's@%PV_ROOT%@'"$PV_ROOT"'@' mysql/persistence.yaml
sed -i 's@%PV_ROOT%@'"$PV_ROOT"'@' prometheus/persistence.yaml
sed -i 's@%PV_ROOT%@'"$PV_ROOT"'@' prometheus/alert-persistence.yaml
sed -i 's@%PV_ROOT%@'"$PV_ROOT"'@' grafana/persistence.yaml
To confirm that the path value has been updated correctly, use the grep
command to print the PV path lines in the YAML files.
grep -r --include="*.yaml" 'path: ' .
output (assuming the
PV_ROOT
is set to/scratch/test
)
./mysql/persistence.yaml: path: "/scratch/test/monitoring/mysql_data"
./grafana/persistence.yaml: path: "/scratch/test/monitoring/grafana"
./prometheus/alert-persistent.yaml: path: "/scratch/test/monitoring/alertmanager"
./prometheus/persistence.yaml: path: "/scratch/test/monitoring/prometheus"
Next: Setting up MYSQL Server