kubectl apply <file.yaml> --save-config
creates or updates a deployment and saves the deployment as metadata.
In the documentation it says
--save-config[=false]: If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future.
Why do I need save-config
? I can still update my deployment using kubectl apply
if I do not --save-config
.
The kubectl command-line tool uses kubeconfig files to find the information it needs to choose a cluster and communicate with the API server of a cluster. Note: A file that is used to configure access to clusters is called a kubeconfig file. This is a generic way of referring to configuration files.
The command set kubectl apply is used at a terminal's command-line window to create or modify Kubernetes resources defined in a manifest file. This is called a declarative usage. The state of the resource is declared in the manifest file, then kubectl apply is used to implement that state.
A kubeconfig file is a file used to configure access to Kubernetes when used in conjunction with the kubectl commandline tool (or other clients).
Kubectl apply apply manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running kubectl apply . This is the recommended way of managing Kubernetes applications on production.
--save-config [=false]: If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future. Why do I need save-config? I can still update my deployment using kubectl apply if I do not --save-config.
Usually, the kubectl apply command is used to create and update objects in a declarative way. For instance, to update/create an object defined in nginx.yaml:
For instance, to update/create an object defined in nginx.yaml: kubectl apply -f nginx.yaml As a reminder, the previous command shows how the apply command is used to create and update kubernetes objects in a declarative fashion.
Check that kubectl is properly configured by getting the cluster state: If you see a URL response, kubectl is correctly configured to access your cluster. If you see a message similar to the following, kubectl is not configured correctly or is not able to connect to a Kubernetes cluster.
kubectl apply
use the data in an annotation kubectl.kubernetes.io/last-applied-configuration
to see e.g. if any fields has been removed since the last apply. This is needed because some fields or annotations may have been added live in the cluster by e.g. a controller or mutating webhook.
See e.g. Understanding the Kubectl Apply Command
I can still update my deployment using kubectl apply if I do not --save-config
Yes, --save-config
is only used when migrating from an imperative workflow. See more details below. The following kubectl apply
commands does not need --save-config
flag because the annotation is already there.
When working with configurations for Kubernetes, this can be done in multiple ways, they are both imperative or declarative:
kubectl apply
is used for declarative configuration management.
Using kubectl
with the --save-config
flag is a way to write config to the annotation kubectl.kubernetes.io/last-applied-configuration
that kubectl apply
uses. This is useful when migrating from an imperative to an declarative workflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With