PodSnapshotPolicy

The PodSnapshotPolicy custom resource defines the following snapshot behavior:

  • Which Pods Google Kubernetes Engine (GKE) takes snapshots of.
  • What triggers a snapshot.
  • Where GKE stores snapshots.
  • How long GKE retains snapshots.

A policy references a PodSnapshotStorageConfig for storage, and GKE creates a PodSnapshot for each snapshot that the policy produces.

For more information, see About GKE Pod snapshots.

PodSnapshotPolicy specification

The following code shows the PodSnapshotPolicy specification:

spec:
  selector:
    matchExpressions:
    - key: string
      operator: string
      values: []string
    matchLabels:
      additionalProperties: string
  storageConfigName: string
  snapshotScope: string
  triggerConfig:
    postCheckpoint: string
    type: string
  retentionConfig:
    lastAccessTimeout: string
  snapshotGroupingRules:
    groupByLabelValue:
      labels: []string
      groupRetentionPolicy:
        maxSnapshotCountPerGroup: int

The following table describes the fields in the PodSnapshotPolicy specification:

Fields

spec.selector

required

object

The set of Pods that this policy manages. The policy's snapshot and restore settings apply to all Pods that match the policy's label selector.

spec.selector.matchExpressions

optional

[]object

A list of label selector requirements. GKE combines the requirements with a logical AND.

spec.selector.matchExpressions[].key

required

string

The label key that the selector applies to.

spec.selector.matchExpressions[].operator

required

string

The relationship between the key and a set of values. Valid operators are In, NotIn, Exists, and DoesNotExist.

spec.selector.matchExpressions[].values

optional

[]string

An array of string values. If the operator is In or NotIn, then the array must contain at least one value. If the operator is Exists or DoesNotExist, then the array must be empty.

spec.selector.matchLabels

optional

object

A map of key-value pairs. Each pair is equivalent to a matchExpressions element whose key field is the pair's key, whose operator field is In, and whose values array contains only the pair's value. GKE combines the requirements with a logical AND.

spec.storageConfigName

required

string

The name of the PodSnapshotStorageConfig that this policy uses to store snapshots.

spec.snapshotScope

optional

string

The scope of the snapshot. The following values are supported:

  • whole-pod (default): captures the entire Pod, including application state, application memory, and file systems.
  • rootfs-only: captures only the container root file system. This value is available in GKE version 1.35.3-gke.1031000 and later.

spec.triggerConfig

required

object

The configuration for snapshot triggers.

spec.triggerConfig.postCheckpoint

optional

string

The behavior of the Pod after GKE takes a snapshot. The following values are supported:

  • stop: the Pod transitions to a completed status after GKE takes the snapshot.
  • resume (default): the workload continues running after the snapshot completes.

spec.triggerConfig.type

required

string

The type of snapshot trigger. The following values are supported:

  • workload: the application inside the Pod signals the GKE agent to take a snapshot.
  • manual: you create a PodSnapshotManualTrigger to take a snapshot.

spec.retentionConfig

optional

object

The retention policy for Pod snapshots. If you don't specify a retention policy, then the Pod snapshot persists until you manually delete it.

spec.retentionConfig.lastAccessTimeout

required

string

The duration of inactivity after which GKE considers the snapshot stale and automatically deletes it. Supported units are y, mo, d, h, and min.

spec.snapshotGroupingRules

optional

object

The rules that GKE uses to group Pod snapshots. This field is available in GKE version 1.35.0-gke.3047000 and later.

spec.snapshotGroupingRules.groupByLabelValue

required

object

Groups Pod snapshots by the values of the specified Pod labels.

spec.snapshotGroupingRules.groupByLabelValue.labels

required

[]string

The Pod label keys that GKE uses to group snapshots. Any matching labels on the source Pod are copied to the PodSnapshot, and a restored Pod must have matching label keys and values to restore from that group.

spec.snapshotGroupingRules.groupByLabelValue.groupRetentionPolicy

optional

object

The retention policy for each snapshot group.

spec.snapshotGroupingRules.groupByLabelValue.groupRetentionPolicy.maxSnapshotCountPerGroup

optional

int

The maximum number of snapshots that GKE retains per group. If the number of Pod snapshots in a group exceeds this value, then GKE automatically deletes the oldest snapshots until the count reaches this value.

The default value is 0, which retains an unlimited number of snapshots per group.

PodSnapshotPolicy status

The status section indicates the observed state of the PodSnapshotPolicy.

The following table describes the fields in the status section:

Fields
status.conditions

array (object)

List of status conditions for the snapshot policy.

status.observedGeneration

integer

The most recent generation that the controller observed.