Kubernetes
Run FastBCP on any Kubernetes cluster (K3s, AKS, EKS, GKE, OpenShift…) as a Job: one export per Job, with the FastBCP Docker image. The license and the credentials stay in Kubernetes Secrets, so any secret store that can deliver a Secret works without change.
Overview
| Item | Value |
|---|---|
| Workload | A Job (batch/v1) with restartPolicy: Never, or a CronJob for scheduled exports |
| Image | arpeio/fastbcp:<version>: tags, volumes and logging settings in Docker |
| License | A Secret mounted as a read-only file, passed to --license |
| Credentials | Secrets read as environment variables |
| Backups | For backup files, a read-only volume with the backup files |
| Result | The Job status follows the FastBCP exit code; the run log is in kubectl logs |
Prerequisites
- A Kubernetes cluster and kubectl: any distribution. The pods need network access to the source database and to the destination.
- A FastBCP license file:
FastBCP.lic, see License.
1. Create the Secrets
# License file and database credentials
kubectl create secret generic fastbcp-license --from-file=FastBCP.lic=./FastBCP.lic
kubectl create secret generic fastbcp-db \
--from-literal=user=FastUser \
--from-literal=password='FastPassword'
# Cloud credentials read by FastBCP from the environment
kubectl create secret generic aws-credentials \
--from-literal=AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
--from-literal=AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
--from-literal=AWS_REGION="${AWS_REGION}"
For S3-compatible storage (MinIO, SeaweedFS…), add the endpoint to the same Secret: --from-literal=S3_ENDPOINT="http://<host>:<port>". See AWS S3.
2. Run the Job
A SQL Server table exported to Parquet files on S3, in 12 parallel chunks:
apiVersion: batch/v1
kind: Job
metadata:
name: fastbcp-orders-export
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: fastbcp
image: arpeio/fastbcp:vX.Y.Z # pin the version you have tested
env:
- name: DB_USER
valueFrom:
secretKeyRef: { name: fastbcp-db, key: user }
- name: DB_PASSWORD
valueFrom:
secretKeyRef: { name: fastbcp-db, key: password }
envFrom:
- secretRef:
name: aws-credentials
args:
- --license
- /secrets/fastbcp/FastBCP.lic
- --connectiontype
- mssql
- --server
- sqlserver.data.svc.cluster.local,1433
- --database
- tpch_test
- --user
- $(DB_USER)
- --password
- $(DB_PASSWORD)
- --query
- SELECT * FROM dbo.orders WHERE year(o_orderdate)=1998
- --fileoutput
- orders.parquet
- --directory
- s3://arpeioftoutput/k8stest/
- --parallelmethod
- Ntile
- --distributekeycolumn
- o_orderkey
- --paralleldegree
- "12"
- --merge
- "false"
- --runid
- orders_export_k8s
volumeMounts:
- name: fastbcp-license
mountPath: /secrets/fastbcp
readOnly: true
volumes:
- name: fastbcp-license
secret:
secretName: fastbcp-license
kubectl apply -f fastbcp-orders-job.yaml
- License as a file: the Secret is mounted under
/secrets/fastbcpand its path is passed to--license. The license stays out of the Job definition and of the process arguments. - Credentials from Secrets:
envandenvFromturn Secret keys into environment variables. FastBCP reads the cloud credentials from the environment itself. $(VAR)inargs: the entrypoint of the image is the FastBCP binary, not a shell, so$VARis not expanded. Kubernetes replaces$(VAR)with the variable before the container starts.
Numbers and booleans in args are quoted ("12", "false"): Kubernetes only accepts strings there.
3. Check the Result
kubectl logs -f job/fastbcp-orders-export
kubectl get job fastbcp-orders-export
| FastBCP exit code | Job status |
|---|---|
0 | Complete |
Any other code, such as 99 (no or invalid license) or 100 (expired license) | Failed; with backoffLimit: 0, the export is not run again |
The log ends with the totals of the run (Total data rows, Total time) and Completed Load. Add --runid to find a run in the log; for other log destinations, see Configuring FastBCP Logging.
Schedule with a CronJob
Put the spec of the Job under jobTemplate, unchanged:
apiVersion: batch/v1
kind: CronJob
metadata:
name: fastbcp-orders-nightly
spec:
schedule: "0 2 * * *" # every day at 02:00
concurrencyPolicy: Forbid # no new run while the previous one is running
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: fastbcp
# image, env, envFrom, args and volumeMounts of the Job
volumes:
# volumes of the Job
To run it now, without waiting for the schedule:
kubectl create job --from=cronjob/fastbcp-orders-nightly fastbcp-orders-now
Backup Files
With --connectiontype backup_mssql, FastBCP reads SQL Server backup files with no SQL Server. Mount the claim of your backup share (NFS, SMB, Azure Files, a cloud disk…) read-only: --server names its directory, --database the files.
apiVersion: batch/v1
kind: Job
metadata:
name: fastbcp-backup-export
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: fastbcp
image: arpeio/fastbcp:vX.Y.Z # pin the version you have tested
envFrom:
- secretRef:
name: aws-credentials
args:
- --license
- /secrets/fastbcp/FastBCP.lic
- --connectiontype
- backup_mssql
- --server
- /backups
- --database
- "tpch_test_*.bak"
- --sourceschema
- dbo
- --sourcetable
- orders
- --fileoutput
- orders.parquet
- --directory
- s3://arpeioftoutput/k8sbackup/
- --parallelmethod
- Physical
- --paralleldegree
- "4"
- --runid
- orders_backup_export_k8s
volumeMounts:
- name: fastbcp-license
mountPath: /secrets/fastbcp
readOnly: true
- name: backups
mountPath: /backups
readOnly: true
volumes:
- name: fastbcp-license
secret:
secretName: fastbcp-license
- name: backups
persistentVolumeClaim:
claimName: mssql-backups # the claim of your backup share
readOnly: true
The image runs as the user fastbcp, uid and gid 10001. It must be able to read the backup files: through their permissions, or with supplementalGroups in the securityContext of the pod naming their group.
Use a Secret Store
FastBCP reads its license from a file path, an HTTPS URL or the license content (--license); it does not connect to secret stores itself. The cluster brings the secret to the pod, in one of three ways:
| Method | What the pod gets | What changes in the Job |
|---|---|---|
| External Secrets Operator | A Kubernetes Secret, kept in sync with the store | Nothing |
| Secrets Store CSI Driver | A file, from a csi volume | The license volume, and a service account |
| Vault Agent Injector | A file in /vault/secrets | Annotations, a service account and the --license path |
The examples use HashiCorp Vault: the license is stored at secret/fastbcp/license, key content, and the Vault role fastbcp is bound to the Kubernetes service account fastbcp. With Azure Key Vault, AWS Secrets Manager or Google Secret Manager, only the store (External Secrets Operator) or the provider (CSI driver) changes: see their documentation.
The Vault side of these examples
# The license file, in the KV v2 engine mounted at secret/
vault kv put secret/fastbcp/license content=- < FastBCP.lic
# Kubernetes authentication, a read-only policy and a role for the fastbcp service account
vault auth enable kubernetes
vault write auth/kubernetes/config kubernetes_host=https://kubernetes.default.svc:443
vault policy write fastbcp - <<'EOF'
path "secret/data/fastbcp/*" {
capabilities = ["read"]
}
EOF
vault write auth/kubernetes/role/fastbcp \
bound_service_account_names=fastbcp \
bound_service_account_namespaces=default \
policies=fastbcp ttl=1h
kubectl create serviceaccount fastbcp
External Secrets Operator
The operator copies the license from the store into the Kubernetes Secret fastbcp-license, and refreshes it. The Job does not change: it mounts that Secret as before.
apiVersion: external-secrets.io/v1
kind: ClusterSecretStore
metadata:
name: vault
spec:
provider:
vault:
server: http://vault.vault.svc:8200
path: secret
version: v2
auth:
kubernetes:
mountPath: kubernetes
role: fastbcp
serviceAccountRef:
name: fastbcp
namespace: default
---
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: fastbcp-license
spec:
refreshInterval: 1h
secretStoreRef:
kind: ClusterSecretStore
name: vault
target:
name: fastbcp-license # the Secret the Job mounts
data:
- secretKey: FastBCP.lic
remoteRef:
key: fastbcp/license
property: content
kubectl apply -f fastbcp-license-externalsecret.yaml
kubectl get externalsecret fastbcp-license # STATUS: SecretSynced
Remove a fastbcp-license Secret created by hand first: the operator creates its own. The same way, an ExternalSecret can fill the Secrets of the database credentials and of the cloud credentials.
Secrets Store CSI Driver
The driver mounts the license as a file, read from the store when the pod starts. Describe the file in a SecretProviderClass:
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
name: fastbcp-license
spec:
provider: vault
parameters:
vaultAddress: http://vault.vault.svc:8200
roleName: fastbcp
objects: |
- objectName: FastBCP.lic
secretPath: secret/data/fastbcp/license
secretKey: content
In the Job, run the pod as the service account the store trusts, and replace the secret volume with a csi volume. The mount path does not change, nor does --license /secrets/fastbcp/FastBCP.lic:
template:
spec:
restartPolicy: Never
serviceAccountName: fastbcp
containers:
# ... unchanged
volumes:
- name: fastbcp-license
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: fastbcp-license
Vault Agent Injector
The injector adds an init container that writes the license to /vault/secrets before FastBCP starts. Add the annotations and the service account to the pod template, drop the fastbcp-license volume and its mount, and point --license to the file:
template:
metadata:
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/agent-pre-populate-only: "true" # init container only: the Job can complete
vault.hashicorp.com/role: fastbcp
vault.hashicorp.com/agent-inject-secret-fastbcp.lic: secret/data/fastbcp/license
vault.hashicorp.com/agent-inject-template-fastbcp.lic: |
{{- with secret "secret/data/fastbcp/license" -}}{{ .Data.data.content }}{{- end -}}
spec:
restartPolicy: Never
serviceAccountName: fastbcp
containers:
- name: fastbcp
image: arpeio/fastbcp:vX.Y.Z
args:
- --license
- /vault/secrets/fastbcp.lic
# ... the other arguments, unchanged
agent-pre-populate-onlykeeps only the init container. Without it, the agent also runs as a sidecar that does not stop, and the Job never completes.- The agent writes the file name in lowercase:
agent-inject-secret-FastBCP.licgives/vault/secrets/fastbcp.lic. Name it in lowercase, as above.
Which One to Choose
- External Secrets Operator is the simplest default: one tool for the license and the passwords, and the Job stays the same.
- Secrets Store CSI Driver keeps the license out of the Kubernetes Secrets: it only exists as a file in the pod.
- Vault Agent Injector fits clusters where Vault and its injector already run.
- The database password and the cloud credentials reach FastBCP as environment variables, so they need a Kubernetes Secret: External Secrets Operator covers them as well as the license.
- A renewed license only needs an update in the store, or of the Secret: no image rebuild, and the next Job uses it.
Related
- Docker: tags, volumes and logging settings of the image
- License: the
--licenseparameter - Authentication: database credentials
- Cloud connectivity: credentials of each destination