find which yaml file was used for the any kubernetes resource?

8/23/2019

How to find, that which yaml file was used for the deployment of any kubernetes resource.

I checked "kubectl describe", it doesn't list the same, is there anyway to know.

use case:

I want to update the yaml and redeploy, one option, I guess is to generate the yaml from running resource, update and redeploy.

any suggestions ?

-- sandejai
kubectl
kubernetes
yaml

2 Answers

8/23/2019

To get yaml for your k8s application deployment.

Use this

kubectl get deploy my-deployment -o yaml --export
 OR
kubectl get pod my-pod -o yaml --export
 OR
kubectl get svc my-svc -o yaml --export

Editing is also simple.

kubectl get deploy my-deployment -o yaml --export > my-deployment.yml
<Edit the my-deployment.yml file and kubectl apply -f my-deployment.yml>

OR 

kubectl edit deployment my-deployment

Hope this helps.

-- mchawre
Source: StackOverflow

8/23/2019

I think you can choose here from two options.

Option 1:

You can grep all YAMLs looking for specific annotations or labels.

$ grep "app: nginx-test" *.yaml

or

$ grep -e "prometheus.io/scheme: http" *.yaml

When you find proper file you can edit it (vi, nano, etc) and apply.

$ kubectl apply -f [yaml-name]

Option 2:

When you know name of your deployment you can edit it.

$ kubectl edit deployment [deployment-name]

You will see current deployment YAML with a status: section which describing current status of deployment. If you don't like vi, you can use nano instead

$ KUBE_EDITOR="nano" kubectl edit [deployment-name]

If you want to create YAML from your current deployment I would advise you to use kubectl edit with --export flag. It will removes unneeded information (like status: from previous comment).

$ kubectl get deploy [your-deployment] -oyaml --export >> newDeployment.yaml

Hope it will help.

-- PjoterS
Source: StackOverflow