How to save SQL storage data in running preemtible instance?

3/28/2019

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

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.

Surprisingly, maybe not, all storage data was erased after a day.

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

-- Ali Tlekbai
devops
gcloud
google-cloud-platform
kubernetes
persistence

3 Answers

3/28/2019

You can make a specific node not preemptible in a Google Kubernetes Engine cluster, as mentioned in the official documentation.

The steps to set up a cluster with both preemptible and non-preemptible node pools are:

  1. Create a Cluster: In the GCP Console, go to Kubernetes Engine -> Create Cluster, and configure the cluster as you need.
  2. On that configuration page, under Node pools, click on Add node pool. Enter the number of nodes for the default and the new pool.
  3. To make one of the pools preemptible, click on the Advance edit button under the pool name, check the Enable preemptible nodes (beta) box, and save the changes.
  4. Click on Create.

Then you probably want to schedule specific pods only on non-preemptible nodes. For this, you can use node taints.

-- alextru
Source: StackOverflow

3/28/2019

You can use managed service from GCP name GKE google kubernetes cluster.

and storage data erased cause of storage class change may not Retain policy and PVC.

better to use managed service i think and i prefer

-- Harsh Manvar
Source: StackOverflow

3/28/2019

I guess I found a solution.

  1. Create a disk on gcloud via:
gcloud compute disks create --size=10GB postgres-disk
gcloud compute disks create --size=[SIZE] [NAME]
  1. Delete any StorageClasses, PV, PVC
  2. Configure deployment file:
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
-- Ali Tlekbai
Source: StackOverflow