Andromeda
Andromeda

Reputation: 1463

Find the history of commands applied to the kubernetes cluster

Is there a way to find the history of commands applied to the kubernetes cluster by kubectl? For example, I want to know the last applied command was

kubectl apply -f x.yaml

or

kubectl apply -f y.yaml

Upvotes: 4

Views: 13330

Answers (1)

Matt
Matt

Reputation: 8162

You can use kubectl apply view-last-applied command to find the last applied configuration:

➜  ~ kubectl apply view-last-applied --help

View the latest last-applied-configuration annotations by type/name or file.

 The default output will be printed to stdout in YAML format. One can use -o option to change output format.

Examples:
  # View the last-applied-configuration annotations by type/name in YAML.
  kubectl apply view-last-applied deployment/nginx
  
  # View the last-applied-configuration annotations by file in JSON
  kubectl apply view-last-applied -f deploy.yaml -o json

[...]    

To get the full history from the beginning of a cluster creation you should use audit logs as already mentioned in comments by @Jonas.

additionally, if you adopt gitops you could have all your cluster state under version control. It will allow you to trace back all the changes made to your cluster.

Upvotes: 1

Related Questions