Whimusical
Whimusical

Reputation: 6649

Revert any changes of a resource to kubectl.kubernetes.io/last-applied-configuration

Is there any command to revert back to previous configuration on a resource?

For example, if I have a Service kind resource created declaratively, and then I change the ports manually, how can I discard live changes so the original definition that created the resource is reapplied?

Is there any tracking on previous applied configs? it could be even nicer if we could say: reconfigure my service to current appied config - 2 versions.

EDIT: I know deployments have rollout options, but I am wondering about a Kind-wise mechanism

Upvotes: 1

Views: 4474

Answers (2)

ulidtko
ulidtko

Reputation: 15570

Since you're asking explicitly about the last-applied-configuration annotation...

Very simple:

kubectl apply view-last-applied deployment/foobar-module | kubectl apply -f -

Given that apply composes via stdin ever so flexibly — there's no dedicated kubectl apply revert-to-last-applied subcommand, as it'd be redundant reimplementation of the simple pipe above.

One could also suspect, that such a revert built-in could never be made perfect, (as Nick_Kh notices) for complicated reasons. A subcommand named revert evokes a lot of expectation from users which it would never fulfill.

So we get a simplified approximation: a spec.bak saved in resource annotations, ready to be re-apply'd.

Upvotes: 7

Nick_Kh
Nick_Kh

Reputation: 5243

Actually, Kubernetes does not support rollback option for the inherent resources besides Deployments and DaemonSets.

However, you can consider to use Helm, which is a well known package manager for Kubernetes. Helm provides a mechanism for restoring previous state for your package release and includes all entire object resources to be reverted.

This feature Helm represents with helm rollback command:

helm rollback [flags] [RELEASE] [REVISION]

Full command options you can find in the official Helm Documentation.

Upvotes: 2

Related Questions