Skip to content

bmaupin/kleanup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI License

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.

Features

  • 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

Examples

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

Usage

  1. 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
    
  2. Export persistent volume claims and add them to the configuration

    kubectl get pvc -o yaml ...
    
  3. Clean up the configuration (with this app)

    ./kleanup configuration-original.yaml > configuration.yaml
    
  4. (Optional) Perform any additional manual cleanup as desired (see below)

  5. (Optional) Parameterize the configs and convert into a Helm chart or OpenShift template

Additional manual cleanup

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
  • 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)

Building cross-platform binaries for releases

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

About

Small utility to clean up Kubernetes/OpenShift configuration exports

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages