<p>I am trying to cut the costs of running the kubernetes cluster on Google Cloud Platform.</p>

<p>I moved my node-pool to preemptible VM instances. I have 1 pod for Postgres and 4 nodes for web apps.
For Postgres, I've created StorageClass to make data persistent.</p>

<p>Surprisingly, maybe not, all storage data was erased after a day.</p>

<p>How to make a specific node in GCP not preemptible?
Or, could you advice what to do in that situation?</p>

<p>I guess I found a solution.</p>

<ol>
<li>Create a disk on gcloud via:</li>
</ol>

<pre><code>gcloud compute disks create --size=10GB postgres-disk
gcloud compute disks create --size=[SIZE] [NAME]
</code></pre>

<ol start="2">
<li>Delete any StorageClasses, PV, PVC</li>
<li>Configure deployment file:</li>
</ol>

<pre><code>apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
        role: postgres
    spec:
      containers:
        - name: postgres
          image: postgres
          env:
            ...
          ports:
            ...
          # Especially this part should be configured!
          volumeMounts:
            - name: postgres-persistent-storage
              mountPath: /var/lib/postgresql
      volumes:
        - name: postgres-persistent-storage
          gcePersistentDisk:
            # This GCE PD must already exist.
            pdName: postgres-disk
            fsType: ext4
</code></pre>
