Recently my Ceph cluster hit 70% utilization. Looking into it, most of the space came from improper usage that had multiplied resource consumption, and cleaning it all up meant doing a migration.
This post records how I migrated a k0s cluster to a k8s cluster. The same playbook also works for moving from any k8s distribution to another one.
Requirements
The original k0s cluster was a single node, deployed to keep things lightweight. In actual use, though, CPU utilization was very low, CPU overcommit was a pain to set up, and the waste was serious.
To improve utilization I used Clonezilla to migrate it into a PVE VM. After the migration the freed-up node was reinstalled and joined the current PVE cluster.
But that brought a new problem. Clonezilla isn’t like an rsync-style backup and restore: the original node had a 480G disk, and the disk after migration had to be larger than the original one. rsync doesn’t have this issue and can follow the actual size.
Since the k0s cluster was using OpenEBS’s hostpath SC StorageClass, both node expansion and later use were problematic. Rather than keep tinkering on that base, it made more sense to migrate every service running on it to a new k8s cluster.
The core requirements:
- Get more resources
- Services work normally after the migration
- No data loss after the migration
Velero Overview
Velero is an open-source tool for safely backing up, restoring and migrating k8s cluster resources and PVCs.
Architecture and workflow
Velero uses a classic client/server (CS) architecture: the server sits in the target k8s cluster, and the client is the local CLI tool.
Velero’s architecture consists of a server component running in the Kubernetes cluster and a command-line client (CLI). It uses Custom Resource Definitions (CRDs) such as Backup, Restore, BackupStorageLocation, VolumeSnapshotLocation, Schedule, PodVolumeBackup, PodVolumeRestore and BackupRepository to manage operations. Controllers inside the Velero server watch these CRD objects and execute the actual backup and restore logic. During this process, Velero talks to the Kubernetes API server to discover resources and communicates with the object storage backend to store backup data.

Environment
The current k0s node has 4c (vCPU), 8g (RAM) and a 500G disk, running version v1.32.2+k0s. The new k8s cluster is a 3 master + 5 worker combination.
The services currently on k0s:
| Service | Description | Notes |
|---|---|---|
| Authentik | Authentication service | |
| cert-manager | Certificate management | |
| harbor | Image registry | |
| ingress-nginx | Ingress | |
| metallb | LB | |
| outline | Documentation hub | |
| mirrors | homelab offline mirror | Uses local-path here, so it has to be rebuilt on the new node first and then the existing content copied into this PVC |
| pve | PVE cluster reverse proxy | |
| haproxy | Ceph rados load balancing | |
| pihole | homelab DNS | pihole is not part of this migration; CoreDNS is used instead |
| externaldns | Internal DNS lookups and resolution for homelab | Connected to CoreDNS after the migration |
| cloudflared | Cloudflare tunnel | Once the service migration is done |
All of these services have to be migrated to the new k8s cluster in full, and every one of them still has to work normally afterwards.
⚠️ Migration notes The IPs MetalLB hands out are involved in internal DNS calls, which will interrupt services and leave them unusable until they are restored.
- The cluster name is different. Anything affected by the cluster name change has to be handled separately once the PVCs have been moved.
- Velero backups need an S3 bucket to hold the backups and to fetch the matching files from during restores.
- The cluster StorageClass is different too, so pay extra attention during the migration.
For S3 I’m using Ceph RGW. Deployment is covered in an earlier post: https://blog.plz.ac/en/posts/cephadm-deploy/
Create the buckets:
s3cmd mb s3://homelab-bootstrap-backup
s3cmd mb s3://k8s-backup
Migration Preparation
The migration flow:
flowchart TD A[Preparation] A1[Verify the target K8s cluster is usable] A2[Deploy and configure Velero\nusing Ceph RGW as backup storage] A3[Prepare target cluster infrastructure:\nMetalLB, Ingress, Cert-Manager] A --> A1 --> A2 --> A3 B[Backup phase (k0s cluster)] B1[Pause writes to critical services\nsuch as Harbor and Outline] B2[Back up namespaces with Velero\nrun velero backup create for each service] B3[Confirm the backups succeeded\nuse velero backup get/describe] B --> B1 --> B2 --> B3 C[Migration phase (K8s cluster)] C1[Deploy Velero and configure RGW storage] C2[Restore base services in order:\nMetalLB -> Ingress -> Cert-Manager -> ExternalDNS] C3[Run velero restore create to restore all services] C --> C1 --> C2 --> C3 D[Post-migration configuration] D1[Check MetalLB IP assignments and DNS consistency] D2[Verify service status: kubectl get pods/services] D3[Verify each service by hand\nsuch as Outline / Harbor / Authentik] D --> D1 --> D2 --> D3 E[Wrap-up] E1[Clean up unneeded Velero backups] E2[Restore production traffic] E3[Update internal docs with the changes] E --> E1 --> E2 --> E3 A --> B --> C --> D --> E
Kubernetes Cluster Deployment
The new k8s cluster:
| hostname | vcpu | memory | disk | ip | role |
|---|---|---|---|---|---|
| infra-master-1 | 4 | 4 | 40 | 10.31.0.110 | master |
| infra-master-2 | 4 | 4 | 40 | 10.31.0.111 | master |
| infra-master-3 | 4 | 4 | 40 | 10.31.0.112 | master |
| infra-worker-1 | 4 | 8 | 40 | 10.31.0.113 | worker |
| infra-worker-2 | 4 | 8 | 40 | 10.31.0.114 | worker |
| infra-worker-3 | 4 | 8 | 40 | 10.31.0.115 | worker |
| infra-worker-4 | 4 | 8 | 40 | 10.31.0.116 | worker |
| infra-worker-5 | 4 | 8 | 40 | 10.31.0.117 | worker |
For installation docs, see the earlier post Deploy Kubernetes Offline with Kubespray
The following plugins need to be enabled:
- ingress-nginx
- cert-manager
- metallb
The cluster also uses two extra IPs:
- 10.31.0.252 DNS
- 10.31.0.253 ingress LB entry
Velero Deployment
Install the Velero CLI. I used Homebrew; install it however you prefer:
brew install velero
Create the credentials file and store the AK and SK in ceph-credentials-velero, with the following content:
[default]
aws_access_key_id = xxx
aws_secret_access_key = xxxxx
The images involved also need to be pulled locally:
docker pull hub.infra.plz.ac/velero/velero:v1.16.1
docker tag hub.infra.plz.ac/velero/velero:v1.16.1 harbor.infra.plz.ac/velero/velero:v1.16.1
docker push harbor.infra.plz.ac/velero/velero:v1.16.1
docker pull hub.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1
docker tag hub.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1 harbor.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1
docker push harbor.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1
Install Velero into the bootstrap cluster
velero install \
--provider aws \
--image harbor.infra.plz.ac/velero/velero:v1.16.1 \
--plugins harbor.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1 \
--bucket homelab-bootstrap-backup \
--secret-file ./ceph-credentials-velero \
--use-volume-snapshots=false \
--backup-location-config \
checksumAlgorithm="",region=default,s3ForcePathStyle=true,s3Url=https://s3.infra.plz.ac \
--use-node-agent
If you’re using MinIO, this config works:
velero install \
--provider aws \
--image harbor.infra.plz.ac/velero/velero:v1.16.1 \
--plugins harbor.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1 \
--bucket velero \
--secret-file ./minio-credentials-velero \
--use-volume-snapshots=false \
--backup-location-config \
region=default,s3ForcePathStyle=true,s3Url=http://10.31.0.5:9000 \
--use-node-agent
Parameter notes:
--provideruses aws here, which is compatible with S3-style storage such as Ceph RGW and MinIO--imageimages are downloaded through a proxy registry built on Cloudflare Workers because of the GFW in mainland China--pluginsthe AWS plugin also comes from the proxy registry--bucketthe bucket created earlier--secret-filethe credentials file created earlier--use-volume-snapshots=falsedisables volume snapshots--backup-location-configthe detailed backup configurationchecksumAlgorithm=""disables the checksum algorithm to work aroundXAmzContentSHA256Mismatcherrors that appear after a proxy or LB (if yours3Urlconnects directly to RGW you can leave this out)region=default: for Ceph RGW the region can be anythings3ForcePathStyle=true: forces path-style (https://s3.infra.plz.ac/bucket), because virtual-host style (bucket.s3.infra.plz.ac) usually has no wildcard DNS in a private deployments3Url=https://s3.infra.plz.acthe URL of the self-hosted S3; here it’s the proxied URL--use-node-agentVelero’s node agent, used to support CSI volume backups
⚠️ The issue below is specific to the k0s distribution. If you’re on another distribution, check where the kubelet directory is.
After deployment I found the node agent failing, and it had to be patched by hand:
kubectl -n velero patch daemonset node-agent \
--type='json' \
-p='[
{
"op": "replace",
"path": "/spec/template/spec/volumes/0/hostPath/path",
"value": "/var/lib/k0s/kubelet/pods"
},
{
"op": "replace",
"path": "/spec/template/spec/containers/0/volumeMounts/0/mountPath",
"value": "/host_pods"
}
]'
Restart the pods:
kubectl -n velero delete pod -l name=node-agent
kubectl get pods -n velero
Here you can see the patched pods are healthy:
NAME READY STATUS RESTARTS AGE
node-agent-kchfj 1/1 Running 0 51s
velero-7756dd8bc6-8phvc 1/1 Running 0 10m
We can create a backup to test it:
velero backup create test-backup --include-namespaces default
Check the details:
velero backup describe test-backup --details
View the backup logs:
velero backup logs test-backup
Execution status:
kubectl logs -f deployment/velero -n velero
Delete the backup:
velero backup delete test-backup
Confirm whether the deletion succeeded:
velero backup get
If you also want to delete the contents in S3, add the --confirm flag:
velero backup delete test-backup --confirm
Migration
StorageClass Configuration
Since different storage is involved here, a separate ConfigMap is needed to tell Velero which StorageClass the restored PVCs should use.
⚠️ Apply this on the new cluster, not the original one
vi change-sc-config.yaml
The content:
apiVersion: v1
kind: ConfigMap
metadata:
# ConfigMap name, can be customized
name: change-sc-config
# Must be Velero's install namespace, usually 'velero'
namespace: velero
# This label is the key: it tells Velero this ConfigMap is used for plugin config
labels:
velero.io/plugin-config: ""
# This label specifies which built-in restore action plugin to use
velero.io/change-storage-class: RestoreItemAction
data:
# The key is the old StorageClass name
openebs-hostpath: csi-rbd-sc # The value is the new StorageClass name
# Add more mappings here if needed, for example:
# another-old-sc: another-new-scApply it:
kubectl apply -f change-sc-config.yaml
Migrating the homelab Offline Mirror
Back up mirrors-nginx
Create the backup:
velero backup create mirrors-nginx-backup --include-namespaces default
Restore:
velero restore create mirrors-nginx-restore --from-backup mirrors-nginx-backup
Migrating Authentik
Back up Authentik
velero backup create authentik-backup --default-volumes-to-fs-backup --include-namespaces authentik
Restore Authentik:
velero restore create authentik-restore --from-backup authentik-backup
# Check whether the PVCs are bound
kubectl get pvc -n authentik
# Check
kubectl get pod,svc,ing -n authentik
Migrating Harbor
Back up Harbor
velero backup create harbor-backup --default-volumes-to-fs-backup --include-namespaces harbor
Restore Harbor. This one is a bit special: the PVC has to be expanded during the restore:
velero restore create harbor-restore --from-backup harbor-backup
kubectl edit pvc harbor-registry -n harbor # Expand this PVC to 100G
# Check whether the PVCs are bound
kubectl get pvc -n harbor
# Check service status
kubectl get pods,svc,ing -n harbor
Migrating Outline
Back up Outline
velero backup create outline-backup --default-volumes-to-fs-backup --include-namespaces outline
Restore Outline:
velero restore create outline-restore --from-backup outline-backup
# Check whether the PVCs are bound
kubectl get pvc -n outline
# Check service status
kubectl get pods,svc,ing -n outline
After the migration, uploads in Outline fail with a permission error. Fix the owner of the uploads directory (match the container’s runtime user; UID 1000 is common):
Error: Permission denied writing to "uploads/e18a9cb4-7088-4c52-a5bd-06305dcf7d12/3171dffb-c75e-48e0-9e47-05134625c6b2/homelab-network.drawio.png". Check the host machine file system permissions.
at /opt/outline/build/plugins/storage/server/api/files.js:47:13
at async apiErrorHandlerMiddleware (/opt/outline/build/server/routes/api/middlewares/apiErrorHandler.js:12:7)
at async apiResponseMiddleware (/opt/outline/build/server/routes/api/middlewares/apiResponse.js:12:5)
at async requestTracerMiddleware (/opt/outline/build/server/middlewares/requestTracer.js:21:5)
at async userAgent (/opt/outline/node_modules/koa-useragent/dist/index.js:12:5)
at async /opt/outline/node_modules/koa-mount/index.js:62:7
at async compressMiddleware (/opt/outline/node_modules/koa-compress/lib/index.js:56:5)
at async logger (/opt/outline/node_modules/koa-logger/index.js:67:7)
Migrating Cloudflared
Back up vpn
velero backup create vpn-backup --default-volumes-to-fs-backup --include-namespaces vpn
Restore vpn:
velero restore create vpn-restore --from-backup vpn-backup
# Check whether the PVCs are bound
kubectl get pvc -n vpn
# Check service status
kubectl get pods,svc,ing -n vpn
DNS Rebuild
After the rebuild, DNS is guaranteed not to work, because the old pi-hole isn’t part of this recovery plan. The plan is to use a lighter DNS setup as the homelab DNS going forward.
The new DNS combination is coredns + etcd + external-dns
A separate namespace is used here for these services:
kubectl create ns dns
The following helm repos need to be added:
helm repo add coredns https://coredns.github.io/helm
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
MetalLB IP Pool
The new cluster only had the plugin enabled at deploy time and no usable IP pool configured, so let’s set one up here:
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default-pool
namespace: metallb
spec:
addresses:
- 10.31.0.253/32
- 10.31.0.252/32
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: default-pool
namespace: metallb
spec:
ipAddressPools:
- default-pool⚠️ Note that both of these IPs were already in use in the k0s cluster, so there will definitely be a conflict once this is enabled. Power off the k0s node before applying. Apply:
kubectl apply -f pool.yaml
Deploying etcd
values/etcd.values.yaml:
global:
security:
allowInsecureImages: true
image:
registry: docker-proxy.plz.ac
clusterDomain: infra.homelab
auth:
rbac:
enabled: false
create: falseApply:
helm install etcd bitnami/etcd -f values/etcd.values.yaml -n dns
Check the service status:
kubectl get pods,svc -n dns
Deploying CoreDNS
values/coredns.values.yaml:
image:
repository: docker-proxy.plz.ac/coredns/coredns
serviceType: LoadBalancer
service:
loadBalancerIP: 10.31.0.252
servers:
- zones:
- zone: .
port: 53
plugins:
- name: errors
- name: health
configBlock: |-
lameduck 10s
- name: ready
- name: kubernetes
parameters: infra.homelab in-addr.arpa
configBlock: |-
pods insecure
fallthrough in-addr.arpa
ttl 30
- name: etcd
configBlock: |-
endpoint http://etcd.dns.svc.infra.homelab:2379
path /skydns
fallthrough
- name: prometheus
parameters: 0.0.0.0:9153
- name: forward
parameters: . 1.1.1.1 8.8.8.8
- name: cache
parameters: 30
- name: loop
- name: reload
- name: loadbalanceApply:
helm install coredns coredns/coredns -f values/coredns.values.yaml -n dns
Check the service status:
kubectl get pods,svc -n dns
Deploying external-dns
Deploying external-dns lets k8s read from the external coredns deployed above, so that every service can get internal host resolution directly from the external DNS.
The corresponding yaml:
global:
security:
allowInsecureImages: true
image:
registry: docker-proxy.plz.ac
provider: coredns
policy: upsert-only
txtOwnerId: "homelab"
extraEnvVars:
- name: ETCD_URLS
value: "http://etcd.dns.svc.infra.homelab:2379"
serviceAccount:
create: true
name: "external-dns"
ingressClassFilters:
- nginxApply:
helm install external-dns bitnami/external-dns -f values/external-dns.values.yaml -n dns
Verifying DNS
You can run a temporary container to look up internal resolution
kubectl run -it --rm --restart=Never --image=harbor.infra.plz.ac/infoblox/dnstools:latest dnstools
Adding External Domains
Since the external-dns here only filters records for Ingresses whose ingressClass is nginx, some external domains won’t get a record and have to be added manually.
Get into the etcd pod:
kubectl get pods -n dns
kubectl exec -it etcd-0 -n dns -- sh
Write a record:
etcdctl put /skydns/ac/plz/infra/s3 '{"host":"10.31.0.7", "ttl":300}'
Query it:
etcdctl get /skydns/ac/plz/infra/s3
Verify
nslookup s3.infra.plz.ac 10.31.0.252
To make the cache take effect quickly, restart the k8s coredns as well:
kubectl rollout restart deployment/coredns -n kube-system
Verification
After verification, every service worked normally with no issues at all, and the old cluster could be destroyed.
Redeploying Velero
Using a different bucket:
velero install \
--provider aws \
--image harbor.infra.plz.ac/velero/velero:v1.16.1 \
--plugins harbor.infra.plz.ac/velero/velero-plugin-for-aws:v1.12.1 \
--bucket k8s-backup \
--secret-file ./ceph-credentials-velero \
--use-volume-snapshots=false \
--backup-location-config \
checksumAlgorithm="",region=default,s3ForcePathStyle=true,s3Url=https://s3.infra.plz.ac \
--use-node-agent
Scheduled Backups
See Velero’s disaster recovery documentation.
Create a schedule that backs up at 7 AM every day:
velero schedule create infra-cluster --schedule "0 7 * * *"
Check the schedule:
velero schedule get
NAME STATUS CREATED SCHEDULE BACKUP TTL LAST BACKUP SELECTOR PAUSED
infra-cluster Enabled 2025-10-02 12:01:37 +0800 CST 0 7 * * * 0s n/a <none> false
Multi-Location Backups
You can set up different backup paths to keep copies on different servers.
For example, one copy locally, one in the cloud, or one on other storage, so that even if the current media fails there is still a backup you can use.
Backing Up to AWS S3
Using AWS S3 as an example here
Create an S3 bucket named slchris-homelab-backup-hk with anonymous access disabled.
In the IAM console, create a dedicated IAM access policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:DeleteObject",
"s3:PutObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Resource": [
"arn:aws:s3:::slchris-homelab-backup-hk/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::slchris-homelab-backup-hk"
]
}
]
}
Create a file named velero-aws-credentials to store the matching AK and SK, in this format:
[aws-s3]
aws_access_key_id=<Your-AWS-Access-Key-ID>
aws_secret_access_key=<Your-AWS-Secret-Access-Key>
Merge it with the earlier config:
cat ceph-credentials-velero velero-aws-credentials >> credentials-combined
Update the config:
kubectl create secret generic cloud-credentials \
--namespace velero \
--from-file=cloud=./credentials-combined \
--dry-run=client -o yaml | kubectl apply -f -
Restart the service:
kubectl rollout restart deployment/velero -n velero
Create the matching BSL
velero backup-location create aws-s3-remote \
--provider aws \
--bucket slchris-homelab-backup-hk \
--config region=ap-east-1,profile=aws-s3
Verify:
velero backup-location get
Create a backup:
velero backup create test-backup-to-hk \
--include-namespaces default \
--storage-location aws-s3-remote \
--wait
Check the backups:
velero backup get
NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR
test-backup Completed 0 0 2025-10-02 13:11:36 +0800 CST 29d default <none>
test-backup-to-hk Completed 0 0 2025-10-02 14:14:47 +0800 CST 29d aws-s3-remote <none>
The backup contents can also be seen in the S3 bucket on the web:

Other
Force Deletion
Force delete: note that this does not delete the actual contents in the bucket
kubectl delete backup test-backup -n velero --force --grace-period=0
Force-kill the restore task
kubectl delete restore authentik-backup-20250607214953 -n velero --grace-period=0 --force
You can also do it with a patch:
kubectl patch restore harbor-restore -n velero -p '{"metadata":{"finalizers":null}}' --type=merge
Uninstall
Uninstall:
velero uninstall
Summary
Velero is a good tool, but doing this manually in an enterprise environment still carries risk. Test it more, and ideally integrate it with your existing platform.
评论