How can I use kubectl --server-dry-run to output the final response body of an apply?

1/31/2019

kubectl supports --server-dry-run so that modifications are not persisted but changes from admission controllers etc. are applied. The default output looks something like the following:

$ kubectl apply --server-dry-run -f deployment.yaml
deployment.apps/nginx-deployment created (server dry run)

However, adding -v=8 shows me the response body with the actual JSON content that will be persisted to etcd. Is there any way to ask kubectl to print that in a nicer format without some crazy grepping etc.?

-- dippynark
kubectl
kubernetes

2 Answers

1/18/2020

You can also use kubectl diff -f deployment.yaml to see what changed.

-- Antoine Pelisse
Source: StackOverflow

2/1/2019

You can get the appropriate Json by using following command:

kubectl apply --server-dry-run - f deployment.yaml -o json
-- Prafull Ladha
Source: StackOverflow