This removes unnecessary objects and parameters from an exported Kubernetes or OpenShift configuration so that it can be more easily managed and optionally turned into a Helm chart or OpenShift template.
- Removes unnecessary objects
- For example, Builds are removed because they're recreated by the BuildConfig
- Removes read-only properties that are set by the server
- For example, creation timestamps, unique IDs, etc
- Removes certain properties when they're set to the default value
- Removes empty or blank properties
Cleaning up the exported configuration from OpenShift's nodejs-mongo-persistent template gives us a file that's over 5 times smaller:
$ oc process openshift//nodejs-mongo-persistent | oc create -f -
$ kubectl get all -o yaml > configuration.yaml && cat configuration.yaml | wc -l
1345
$ ./kleanup configuration.yaml | wc -l
247
If the number of pods is scaled up the difference is even greater:
$ kubectl scale dc nodejs-mongo-persistent --replicas=3
$ kubectl get all -o yaml > configuration.yaml && cat configuration.yaml | wc -l
1660
$ ./kleanup configuration.yaml | wc -l
247
-
Export the configuration
kubectl get all --export -o yaml > configuration-original.yaml
Or:
kubectl get all --export -o yaml -l app=appname > configuration-original.yaml
-
Export persistent volume claims and add them to the configuration
kubectl get pvc -o yaml ...
-
Clean up the configuration (with this app)
./kleanup configuration-original.yaml > configuration.yaml
-
(Optional) Perform any additional manual cleanup as desired (see below)
-
(Optional) Parameterize the configs and convert into a Helm chart or OpenShift template
There's some additional manual cleanup that can be performed depending on your situation:
- BuildConfig.spec.strategy.dockerStrategy.from.kind
- (To be confirmed) Can be removed (along with BuildConfig.spec.strategy.dockerStrategy.from.name)
if it's set to
ImageStreamTag
and you're using the Dockerfile in your Git repo
- (To be confirmed) Can be removed (along with BuildConfig.spec.strategy.dockerStrategy.from.name)
if it's set to
- BuildConfig.spec.strategy.sourceStrategy.from.namespace
- Can be removed if same as current namespace
- DeploymentConfig.spec.template.triggers.imageChangeParams.from.namespace
- Can be removed if same as current namespace
- DeploymentConfig.spec.template.spec.containers.image
- Can be removed if the deployment config has an ImageChange trigger (it will recreate this setting automatically)
- Route.host
- Can be removed if you're not customizing it (it will be autogenerated)
go build
tar -cvzf kleanup-linux-64bit.tar.gz kleanup
GOOS=windows GOARCH=amd64 go build
zip kleanup-windows-64bit.zip kleanup.exe
GOOS=darwin GOARCH=amd64 go build
zip kleanup-mac-64bit.zip kleanup
rm kleanup kleanup.exe