This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Kubernetes to Bucket

Synchronize Kubernetes objects into a Bucket

1 - Introduction

Kubernetes to Bucket introduction

Kubernetes objects can be synchronized into a Bucket the kubernetes-to-bucket plugin.

Synchronization process

Special rules

There are no special rules for this synchronization plugin.

Blacklisted objects

There are some Kubernetes objects that are blacklisted by default and will be ignored by the synchronization process.

This is the list of the blacklisted objects:

  • Namespaces which name starts with kube- or openshift , an the Namespace resiliency-operator.
  • All namespaced objects inside a blacklisted Namespace.
  • ConfigMaps named kube-root-ca.crt or openshift-service-ca.crt.

Objects path

Each Kubernetes object will be stored into a file with the following path: <group>.<version>.<kind>/<object_namespace>.<object_name>.

Examples:

  • The Namespace named test will be saved in the file core.v1.Namespace/test.
  • The Deployment named app-1 deployed in the test Namespace will be saved in the file apps.v1.Deployment/test.app-1.

Use cases

Backups

Backup your Kubernetes cluster to a Bucket to recover data when required.

Pilot light architecture

Synchronize applications to a Bucket and recover the applications in another cluster after a disaster.

2 - Configuration

Kubernetes to Bucket configuration

Introduction

The synchronization process can be configured with some specific parameters using the .spec.config attribute.

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...

Required configuration

Source and destination

The source cluster and the destination bucket can be specified using the .spec.config.sourceName and .spec.config.destinationName properties. Both the KubernetesCluster and the bucket objects should exists in the same Namespace where the synchronization is being created.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    sourceName: cluster-1
    destinationName: bucket-1
    ...

Optional configuration

Selectors

The resources that should be synchronized can be configured using the .spec.config.selectors property. If not configured, all resources will be included in the synchronization.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    selectors:
      - target:
          version: v1
          resources:
            - namespaces
        objectSelector:
          labelSelector:
            matchLabels:
              disaster-recovery: "true"

Global selectors

Global selectors are used to set the default value on all selectors defined in .spec.config.selectors. They can be configured with the .spec.config.globalSelector property.

There are two options allowed, that can be configured at the same time:

  • namespaceSelector: to set e dafult namespace selector for namespaced resources
  • objectSelector: to set a default object selector for all resources

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    globalSelector:
      namespaceSelector:
        labelSelector:
          matchLabels:
            env: pro
      objectSelector:
        labelSelector:
          matchLabels:
            env: pro

Path prefix

The Kubernetes objects can be written in a subdirectory of the destination Bucket. The property .spec.config.pathPrefix allows this configuration.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    pathPrefix: prefix-path

Log level

The log level of the Pod deployed to execute the synchronization, can be configured with the .spec.config.logLevel parameter.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    logLevel: warn

Observability

Observability can be enaled using the specific .spec.config.observability parameter. For more information check the Observability page.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    observability:
      enabled: true
      interval: 2m

Limit assigned resources

For each synchronization, a new Pod is deployed inside the same Namespace. The limit and requests resources can be set using the .spec.config.resources field.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    resources:
      requests:
        cpu: 1
        memory: 2Gi
      limits:
        cpu: 2
        memory: 2Gi

Concurrency

The concurrency parameter can be used to improve the peformance of the synchronization process with .spec.config.concurrency`.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    concurrency: 200

Transformations

Kubernetes obejcts from the source cluster can be transformed before being synchronized into the destination bucket.

Example:

apiVersion: automation.astronetes.io/v1alpha1
kind: Synchronization
metadata:
  name: example
spec:
  plugin: kubernetes-to-bucket
  config:
    ...
    transformations:
      resources:
        - version: v1
          resources:
            - namespaces
      operations:
        - jsonpatch:
            operations:
              - op: add
                path: /metadata/labels/test-astrosync
                value: ok

3 - Observability

Obervability

Introduction

The synchronization process exports many metrics in Prometheus format over HTTP.

Exported metrics

The following metrics are available:

MetricDescription
astronetes_synchronization_statusThe status of each synchronization object.
astronetes_synchronization_status_totalThe count of synchronization objects for each state.

Requirements

  • The ServiceMonitor CRD from prometheus (servicemonitors.monitoring.coreos.com) must be enabled in the cluster where the operator is running.

Processes

Enable observability

Update the synchronization configuration, setting the paramente .spec.config.observability.enabled to true.

Once enabled the observability, a ServiceMonitor will be created in the same Namespace of the related synchronization.

Disable observability

Update the synchronization configuration, setting the paramente .spec.config.observability.enabled to false.

4 - API Reference

Configuration details

Config

Configuration for Kubernetes to Bucket synchronization

FieldDescriptionTypeRequired
concurrencyConcurrent processes to be executed to improve performanceintfalse
destinationNameBucket name where data will be synchronizedstringtrue
globalSelectorOverrides selectors propertiesKubernetesGlobalSelectorfalse
logLevelLog level to be used by the synchronization Podstringfalse
observabilityObservability configurationObservabilityConfigfalse
optionsSynchronization optionsSynchronizationOptionsfalse
pathPrefixPath prefix to be used to retreive objects in the Bucketstringtrue
resourcesResources to be assigned to the synchronization PodResourceRequirementsfalse
selectorsSelectors to filter the Kubernetes resources to be synchronized[]KubernetesObjectSelectorfalse
sourceNameKubernetesCluster name from where data will be readstringtrue
transformationsTransform Kubernetes objects before to be written to the destination[]Transformationsfalse
useCachedDataUse cached data instead of get data from assets on startupboolfalse

KubernetesGlobalSelector

Global selector is used to set the default value on all selectors. All defined selectors are combined using AND logic.

FieldDescriptionTypeRequired
objectSelectorRules to filter Kubernetes objects by ObjectSelectorObjectSelectorfalse
namespaceSelectorRules to filter Kubernetes objects by NamespaceSelectorNamespaceSelectorfalse

ObjectSelector

FieldDescriptionTypeRequired
nameSelectorFilter objects by their nameNameSelectorfalse
labelSelectorFilter objects by their labelsLabelSelectorfalse

NameSelector

Select object by their name

FieldDescriptionTypeRequired
includeRegexInclude names that matches at least one regex[]stringfalse
excludeRegexExlcude names that matches at least one regex[]stringfalse

LabelSelector

Select object by their labels

FieldDescriptionTypeRequired
matchLabelsMatch object by the given labelsmap[string]stringfalse
matchExpressionsMatch object by the given expressions[]LabelSelectorRequirementfalse

LabelSelectorRequirement

A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values.

FieldDescriptionTypeRequired
keykey is the label key that the selector applies to.stringtrue
operatoroperator represents a key’s relationship to a set of values.Valid operators are In, NotIn, Exists and DoesNotExist.LabelSelectorOperatortrue
valuesvalues is an array of string values. If the operator is In or NotIn,the values array must be non-empty. If the operator is Exists or DoesNotExist,the values array must be empty. This array is replaced during a strategicmerge patch.+optional+listType=atomic[]stringfalse

LabelSelectorOperator

A label selector operator is the set of operators that can be used in a selector requirement.

FieldDescriptionTypeRequired

NamespaceSelector

FieldDescriptionTypeRequired
nameSelectorFilter Namespaces by their nameNameSelectorfalse
labelSelectorFilter Namespaces by their labelsLabelSelectorfalse

ObservabilityConfig

Configure the synchronization process observability using Prometheus ServiceMonitor

FieldDescriptionTypeRequired
enabledEnable the Observability with a Prometheus ServiceMonitorboolfalse
intervalConfigure the interval in the ServiceMonitor that Prometheus will use to scrape metricsDurationfalse

Duration

Duration is a wrapper around time.Duration which supports correct marshaling to YAML and JSON. In particular, it marshals into strings, which can be used as map keys in json.

FieldDescriptionTypeRequired

SynchronizationOptions

Customize the synchronization process with special options

FieldDescriptionTypeRequired
dryRunSimulate the synchronization process but don’t execute the write operationsboolfalse
forceSyncSynchronize object in the destination even if the object exists in the destination and it doesn’t match the configured selectorsboolfalse
forcePrunePrune object in the destination even if it doesn’t match the configured selectorsboolfalse
showLogIfObjectIsAlreadyInSyncShow a log message if object is already in syncboolfalse
showLogIfObjectHaveBeenAdaptedShow a log message if object have been adapted for the destinationboolfalse

KubernetesObjectSelector

All defined selectors are combined using AND logic.

FieldDescriptionTypeRequired
objectSelectorFilter objects by ObjectSelectorObjectSelectorfalse
namespaceSelectorFilter objects by NamespaceSelectorNamespaceSelectorfalse
targetKubernetes resource to be usedGroupVersionResourcesfalse

GroupVersionResources

Select a set of GroupVersionResource

FieldDescriptionTypeRequired
groupKubernetes resource group. Example: appsstringtrue
versionKubernetes resource version. Example: v1stringtrue
resourcesKubernetes resource names. Example: deployments[]stringfalse

Transformations

Transformations is a list of operations to modifiy the Kubernetes objects matching the given selectors

FieldDescriptionTypeRequired
resourcesSelect the objects to be transfomred by their resource type[]GroupVersionResourcesfalse
namespaceSelectorFilter the objects to be transformed by NamespaceSelectorNamespaceSelectorfalse
objectSelectorFilter the objects to be transformed by ObjectSelectorObjectSelectorfalse
operationsOperations to be executed to transform the objects[]TransformationOperationfalse

TransformationOperation

The operation to execute to transform the objects

FieldDescriptionTypeRequired
envVariableConfigure environment variablesOperationEnvVariablefalse
jsonpatchJSONPatch operationOperationJSONPatchfalse
jsonpointerJSONPointer operationOperationJSONPointerfalse

OperationEnvVariable

EnvVariable operation

FieldDescriptionTypeRequired
opOperation to be executed: delete, set, updateSetEnvOptrue
containerSelectorSelect the containers to transformEnvVariableContainerSelectortrue
regexOptional regex to match and replace valuestringfalse
nameName of the environment variable to transformstringtrue
valueValue to be assigned to the environment variablestringtrue

SetEnvOp

FieldDescriptionTypeRequired

EnvVariableContainerSelector

FieldDescriptionTypeRequired
nameOptional name of the container to be transformedstringfalse
typeType of container to be transformed: Container, InitContainer, AllContainerSelectorTypefalse

ContainerSelectorType

FieldDescriptionTypeRequired

OperationJSONPatch

The JSONPatch operation

FieldDescriptionTypeRequired
skipIfNotFoundOnDeleteSkip if not found on deletebooltrue
operationsList of operations to be executed[]JSONPatchOperationtrue

JSONPatchOperation

JSONPAtch operation

FieldDescriptionTypeRequired
opJSONPatch operation: add, copy, move, remove, replace, teststringtrue
pathExecute the operation to the given pathstringtrue
valueOptional value to be used in the operationinterface{}true

OperationJSONPointer

JSONPointer operation

FieldDescriptionTypeRequired
opOperation to be executed: updateJSONPointerOperationtrue
pathExecute the operation in the given pathstringtrue
regexOptional regex to match and replace valuestringfalse
valueValue to be used in the operationstringtrue

JSONPointerOperation

FieldDescriptionTypeRequired