@Manolis Kaliotis you can output the construct of resource to yaml before creati . . .

Subrata Biswas:
@Manolis Kaliotis you can output the construct of resource to yaml before creating it from imperative command by using --dry-run=client and - o yaml arguments and then you can modify the yaml and can use imperative kubectl apply -f resource.yaml to create it. for example if you run "kubectl run --dry-run=client nginx --image=nginx --port=80 -o yaml > nginx.yaml " then it will output the entire resource construct of pod to nginx.yaml file but will not create the pod . Then you can use editor like vi or vim to edit and make necessary changes and run kubectl apply -f nginx.yaml to create object. On the other hand you can get entire construct from a created and running object too. For example you have pod running named nginx and you can run “kubectl get pod nginx -o yaml > nginx.yaml” This will output the entire pod construct to nginx.yaml. Now if you make change you will need to delete the pod and run kubectl apply -f nginx.yaml , but if it is a deployment then you dont need to delete it and you can directly run kubectl apply as it accepts replace/edit operation.

Manolis Kaliotis:
Thanks @Subrata Biswas, I was looking for a more general way to check. As an example, you have your resources yaml files and all created via declarative way. But after some kubectl imperative actions on them those files do not represent the running state any more. So one way that would seem right is to get the yaml of the running resource and compare it to the static file to spot any difference. Is there any let’s say more general concept to check the consistency on those static files, if let’s say someone alters the running resources with kubectl commands.

Subrata Biswas:
@Manolis Kaliotis you can use kustomize , kubeclt diff -k ./nameoffile . https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/ to closely do that work , but has some limitations