Reputation: 463
I'm looking for a way to export a yaml file from a deployed component but without the cluster specific information.
kubectl get MYOBJECT --export -o yaml > my.yaml
but since "export" is now deprecated (since 1.14 and should normally disappear in 1.18 (didn't find it in changelog), what would be an alternative ?
thanks
Upvotes: 43
Views: 37585
Reputation: 93203
solution with ZERO dependencies to any 3rd-party tool:
kubectl -n $ns get [resourcetype] [resourcename] |\
sed '/^ uid: /d; /^ resourceVersion: /d; /^ creationTimestamp: /d; /^ selfLink: /d; /^status:$/Q;'
Upvotes: 0
Reputation: 199
Export is deprecated in latest version of Kube or Openshift. We can directly do it like below
oc get virtualservices -o yaml > project.yaml
oc get routes -o yaml > project.yaml
Upvotes: 0
Reputation: 810
Finally an easy to use tool has been created: https://github.com/itaysk/kubectl-neat
You could easily install all it as a kubectl krew plugin:
kubectl krew install neat
Usage as well is pretty simple
kubectl get pod mypod -o yaml | kubectl neat
Upvotes: 14
Reputation: 849
For anyone using yq
v4.x you can do the following to get what you need:
kubectl get <resource> -n <namespace> <resource-name> -o yaml \
| yq eval 'del(.metadata.resourceVersion, .metadata.uid, .metadata.annotations, .metadata.creationTimestamp, .metadata.selfLink, .metadata.managedFields)' -
Upvotes: 5
Reputation: 145
Using JQ does the trick.
kubectl get secret <secretname> -ojson | jq 'del(.metadata.namespace,.metadata.resourceVersion,.metadata.uid) | .metadata.creationTimestamp=null'
produces exactly the same JSON as
kubectl get secret <secretname> -ojson --export
Upvotes: 15
Reputation: 810
Based on the above input, I created a short at our fubectl project: https://github.com/kubermatic/fubectl/pull/58
hopefully it helps also for others:
kget-ex RESOURCE > export.yaml
Upvotes: 0
Reputation: 2524
Another option is to make use of the annotation field kubectl.kubernetes.io/last-applied-configuration
which holds the resource initial applied configuraiton without auto-generated fields.
Example:
kubectl get <resource kind> <resource name> -o yaml | \
yq r - 'metadata.annotations."kubectl.kubernetes.io/last-applied-configuration"'
Upvotes: 5
Reputation: 5415
If you want to use YAML input / output, you can use yq.
This did the trick for me, add or remove filters as appropriate for you:
kubectl get secret "my_secret" -n "my_namespace" --context "my_context" -o yaml \
| yq d - 'metadata.resourceVersion' \
| yq d - 'metadata.uid' \
| yq d - 'metadata.annotations' \
| yq d - 'metadata.creationTimestamp' \
| yq d - 'metadata.selfLink'
Upvotes: 12
Reputation: 6471
Currently the one option is to do -o yaml
or -o json
and remove the unnecessary fields
Upvotes: 7
Reputation: 54211
There is no consistent way to do this since there is no overall guidelines about defaulting and other live data clean up. That is why it was deprecated. You should keep your source files in git or similar.
Upvotes: 10