Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need save-config with kubctl apply?

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.

like image 974
User12547645 Avatar asked Apr 04 '21 14:04

User12547645


People also ask

What is the purpose of Kubernetes configuration file?

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.

What happens when you kubectl apply?

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.

What is kubectl config file?

A kubeconfig file is a file used to configure access to Kubernetes when used in conjunction with the kubectl commandline tool (or other clients).

What is in kubectl apply command?

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.

What does save-config do in kubectl?

--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.

What is the kubectl apply command?

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:

How to create and update Kubernetes objects using kubectl?

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.

How do I know if kubectl is configured correctly?

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.


1 Answers

kubectl apply

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.

Workflows with kubectl

When working with configurations for Kubernetes, this can be done in multiple ways, they are both imperative or declarative:

  • Managing Kubernetes Objects Using Imperative Commands
  • Imperative Management of Kubernetes Objects Using Configuration Files
  • Declarative Management of Kubernetes Objects Using Configuration Files

kubectl apply is used for declarative configuration management.

Migrating from imperative to declarative config mangement

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.

  • Migrating from imperative command management to declarative object configuration
  • Migrating from imperative object configuration to declarative object configuration
like image 160
Jonas Avatar answered Oct 23 '22 10:10

Jonas