This is the multi-page printable view of this section. Click here to print.
Kubernetes to Bucket
1 - 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-oropenshift, an the Namespaceresiliency-operator. - All namespaced objects inside a blacklisted Namespace.
- ConfigMaps named
kube-root-ca.crtoropenshift-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
testwill be saved in the filecore.v1.Namespace/test. - The Deployment named
app-1deployed in thetestNamespace will be saved in the fileapps.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
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 resourcesobjectSelector: 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.
info.
Accepted values: debug, info, warn, error.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.
Default value:
enabled: false
interval: 60s
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`.
100.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
Introduction
The synchronization process exports many metrics in Prometheus format over HTTP.
Exported metrics
The following metrics are available:
| Metric | Description |
|---|---|
astronetes_synchronization_status | The status of each synchronization object. |
astronetes_synchronization_status_total | The count of synchronization objects for each state. |
Requirements
- The
ServiceMonitorCRD 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
Config
Configuration for Kubernetes to Bucket synchronization
| Field | Description | Type | Required |
|---|---|---|---|
concurrency | Concurrent processes to be executed to improve performance | int | false |
destinationName | Bucket name where data will be synchronized | string | true |
globalSelector | Overrides selectors properties | KubernetesGlobalSelector | false |
logLevel | Log level to be used by the synchronization Pod | string | false |
observability | Observability configuration | ObservabilityConfig | false |
options | Synchronization options | SynchronizationOptions | false |
pathPrefix | Path prefix to be used to retreive objects in the Bucket | string | true |
resources | Resources to be assigned to the synchronization Pod | ResourceRequirements | false |
selectors | Selectors to filter the Kubernetes resources to be synchronized | []KubernetesObjectSelector | false |
sourceName | KubernetesCluster name from where data will be read | string | true |
transformations | Transform Kubernetes objects before to be written to the destination | []Transformations | false |
useCachedData | Use cached data instead of get data from assets on startup | bool | false |
KubernetesGlobalSelector
Global selector is used to set the default value on all selectors. All defined selectors are combined using AND logic.
| Field | Description | Type | Required |
|---|---|---|---|
objectSelector | Rules to filter Kubernetes objects by ObjectSelector | ObjectSelector | false |
namespaceSelector | Rules to filter Kubernetes objects by NamespaceSelector | NamespaceSelector | false |
ObjectSelector
| Field | Description | Type | Required |
|---|---|---|---|
nameSelector | Filter objects by their name | NameSelector | false |
labelSelector | Filter objects by their labels | LabelSelector | false |
NameSelector
Select object by their name
| Field | Description | Type | Required |
|---|---|---|---|
includeRegex | Include names that matches at least one regex | []string | false |
excludeRegex | Exlcude names that matches at least one regex | []string | false |
LabelSelector
Select object by their labels
| Field | Description | Type | Required |
|---|---|---|---|
matchLabels | Match object by the given labels | map[string]string | false |
matchExpressions | Match object by the given expressions | []LabelSelectorRequirement | false |
LabelSelectorRequirement
A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values.
| Field | Description | Type | Required |
|---|---|---|---|
key | key is the label key that the selector applies to. | string | true |
operator | operator represents a key’s relationship to a set of values.Valid operators are In, NotIn, Exists and DoesNotExist. | LabelSelectorOperator | true |
values | values 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 | []string | false |
LabelSelectorOperator
A label selector operator is the set of operators that can be used in a selector requirement.
| Field | Description | Type | Required |
|---|
NamespaceSelector
| Field | Description | Type | Required |
|---|---|---|---|
nameSelector | Filter Namespaces by their name | NameSelector | false |
labelSelector | Filter Namespaces by their labels | LabelSelector | false |
ObservabilityConfig
Configure the synchronization process observability using Prometheus ServiceMonitor
| Field | Description | Type | Required |
|---|---|---|---|
enabled | Enable the Observability with a Prometheus ServiceMonitor | bool | false |
interval | Configure the interval in the ServiceMonitor that Prometheus will use to scrape metrics | Duration | false |
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.
| Field | Description | Type | Required |
|---|
SynchronizationOptions
Customize the synchronization process with special options
| Field | Description | Type | Required |
|---|---|---|---|
dryRun | Simulate the synchronization process but don’t execute the write operations | bool | false |
forceSync | Synchronize object in the destination even if the object exists in the destination and it doesn’t match the configured selectors | bool | false |
forcePrune | Prune object in the destination even if it doesn’t match the configured selectors | bool | false |
showLogIfObjectIsAlreadyInSync | Show a log message if object is already in sync | bool | false |
showLogIfObjectHaveBeenAdapted | Show a log message if object have been adapted for the destination | bool | false |
KubernetesObjectSelector
All defined selectors are combined using AND logic.
| Field | Description | Type | Required |
|---|---|---|---|
objectSelector | Filter objects by ObjectSelector | ObjectSelector | false |
namespaceSelector | Filter objects by NamespaceSelector | NamespaceSelector | false |
target | Kubernetes resource to be used | GroupVersionResources | false |
GroupVersionResources
Select a set of GroupVersionResource
| Field | Description | Type | Required |
|---|---|---|---|
group | Kubernetes resource group. Example: apps | string | true |
version | Kubernetes resource version. Example: v1 | string | true |
resources | Kubernetes resource names. Example: deployments | []string | false |
Transformations
Transformations is a list of operations to modifiy the Kubernetes objects matching the given selectors
| Field | Description | Type | Required |
|---|---|---|---|
resources | Select the objects to be transfomred by their resource type | []GroupVersionResources | false |
namespaceSelector | Filter the objects to be transformed by NamespaceSelector | NamespaceSelector | false |
objectSelector | Filter the objects to be transformed by ObjectSelector | ObjectSelector | false |
operations | Operations to be executed to transform the objects | []TransformationOperation | false |
TransformationOperation
The operation to execute to transform the objects
| Field | Description | Type | Required |
|---|---|---|---|
envVariable | Configure environment variables | OperationEnvVariable | false |
jsonpatch | JSONPatch operation | OperationJSONPatch | false |
jsonpointer | JSONPointer operation | OperationJSONPointer | false |
OperationEnvVariable
EnvVariable operation
| Field | Description | Type | Required |
|---|---|---|---|
op | Operation to be executed: delete, set, update | SetEnvOp | true |
containerSelector | Select the containers to transform | EnvVariableContainerSelector | true |
regex | Optional regex to match and replace value | string | false |
name | Name of the environment variable to transform | string | true |
value | Value to be assigned to the environment variable | string | true |
SetEnvOp
| Field | Description | Type | Required |
|---|
EnvVariableContainerSelector
| Field | Description | Type | Required |
|---|---|---|---|
name | Optional name of the container to be transformed | string | false |
type | Type of container to be transformed: Container, InitContainer, All | ContainerSelectorType | false |
ContainerSelectorType
| Field | Description | Type | Required |
|---|
OperationJSONPatch
The JSONPatch operation
| Field | Description | Type | Required |
|---|---|---|---|
skipIfNotFoundOnDelete | Skip if not found on delete | bool | true |
operations | List of operations to be executed | []JSONPatchOperation | true |
JSONPatchOperation
JSONPAtch operation
| Field | Description | Type | Required |
|---|---|---|---|
op | JSONPatch operation: add, copy, move, remove, replace, test | string | true |
path | Execute the operation to the given path | string | true |
value | Optional value to be used in the operation | interface{} | true |
OperationJSONPointer
JSONPointer operation
| Field | Description | Type | Required |
|---|---|---|---|
op | Operation to be executed: update | JSONPointerOperation | true |
path | Execute the operation in the given path | string | true |
regex | Optional regex to match and replace value | string | false |
value | Value to be used in the operation | string | true |
JSONPointerOperation
| Field | Description | Type | Required |
|---|