Deploy Grafana with existing PV#
The goal of this documentation is to be able to redeploy Grafana from an existing PV when there is no longer a statefulset and PVC.
Variable:
CLIENT=xxx
Step 1 : Get a PVC definition on another zone#
kswitch svc-grafana-client-pf
kubectl get pvc -n grafana-client-obs-pf storage-grafana-obs-pf-0 -o yaml > /tmp/def_pvc.yaml
Step 2 : Edit PVC definition with zone parameters#
Connect to the zone:
kswitch svc-grafana-client-${CLIENT}
Modify client name:
sed -i "s/obs-pf/obs-${CLIENT}/g" /tmp/def_pvc.yaml
Edit PV reference:
pv_name=$(kubectl get pv -o json | jq -r --arg contract "obs-${CLIENT}" '.items[] | select(.spec.claimRef.name == "storage-grafana-"+$contract+"-0") | .metadata.name')
sed -i "s/volumeName: *.*$/volumeName: ${pv_name}/g" /tmp/def_pvc.yaml
Update PV size (possibly it will be the same size):
storage_size=$(kubectl get pv -o json | jq -r --arg contract "obs-${CLIENT}" '.items[] | select(.spec.claimRef.name == "storage-grafana-"+$contract+"-0") | .spec.capacity.storage')
sed -i "s/storage: *.*$/storage: ${storage_size}/g" /tmp/def_pvc.yaml
Verify definition:
echo ${pv_name}
echo ${storage_size}
cat /tmp/def_pvc.yaml
Expected result:
- same PV name
- storage size is correct
- no old reference to obs-pf
Step 3 : Ensure that the PV is available#
kubectl patch "pv/${pv_name}" --type json -p='[{"op": "remove", "path": "/spec/claimRef"}]'
kubectl get pv "${pv_name}" -o jsonpath="{ .status.phase }"
Available.
Step 4 : Apply PVC with new parameters#
This step allows you to have a PVC which is directly attached to the already existing PV.
kubectl apply -f /tmp/def_pvc.yaml
Step 5 : apply with trackbone#
This step will only redeploy the statefulset.
cd contexts/ngot
trackbone apply -z svc-grafana-client-${CLIENT} -c grafana