The last-applied-configuration annotation stores the configuration most recently applied by kubectl. When kubectl apply runs again, it uses this stored configuration to calculate changes to the Kubernetes API object. section 15.1.2
The annotation is managed internally by kubectl and can make an object’s metadata verbose. It may appear in an object’s YAML or JSON definition but is not shown by kubectl describe; it may eventually be deprecated and removed. section 7.5.3
Use the annotation carefully when fields are omitted from manifests:
- If a Deployment manifest omits replicas, the API sets replicas to 1; a later kubectl apply can therefore reduce an intentionally scaled Deployment. section 15.1.2
- Repair the stored configuration by editing the last-applied configuration and removing replicas, so future applies no longer overwrite the desired replica count when that field remains omitted. section 15.1.2
- Avoid the problem by omitting replicas from the original manifest, then scale the Deployment separately to suit demand. section 15.1.2
Repair the stored applied configuration
Run `kubectl apply edit-last-applied deploy kiada`. An editor opens the Deployment’s stored last-applied configuration; remove the replicas field, save, and close it. Subsequent kubectl apply operations no longer overwrite the Deployment’s separately managed replica count. section 15.1.2
$ kubectl apply edit-last-applied deploy kiada
Use the command listing to open and edit a Deployment’s stored last-applied configuration. section 15.1.2
