问题
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
回答1:
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.
回答2:
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'
回答3:
Currently the one option is to do -o yaml
or -o json
and remove the unnecessary fields
回答4:
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
回答5:
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"'
回答6:
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
来源:https://stackoverflow.com/questions/61392206/kubectl-export-is-deprecated-any-alternative