Skip to content

Declarative resource management

Declarative resource management is a configuration approach used in Kubernetes where resources are defined and managed through YAML manifests rather than a series of imperative commands^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

Core Characteristics

In the declarative model, the user defines the desired state of a resource (such as a Service or Deployment) in a file, and the system reconciles the actual state with this desired state^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

A common method for creating resources declaratively involves using the kubectl create command with the -f flag, pointing to a configuration file^[400-devops-06-kubernetes-k8s-paas-03k8s.md]. For example, to create a service, one would execute: kubectl create -f nginx-ds-svc.yaml^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

Resource Definition

Resources are defined using structured YAML files, sometimes referred to as "resource configuration lists" or manifests^[400-devops-06-kubernetes-k8s-paas-03k8s.md]. These files specify the apiVersion, kind, metadata, and spec of the resource^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

Modifications

Modifications to existing resources can be performed in two ways when using declarative configurations^[400-devops-06-kubernetes-k8s-paas-03k8s.md]: * Online: Using kubectl edit <resource-type> <resource-name> to modify the live resource directly^[400-devops-06-kubernetes-k8s-paas-03k8s.md]. * Offline: Modifying the local YAML file and re-applying it^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

The offline method is often preferred for version control, as changes are recorded in the file history^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

Deletion

Deletion is handled by applying the delete operation against the configuration file^[400-devops-06-kubernetes-k8s-paas-03k8s.md]. kubectl delete -f <filename>.yaml^[400-devops-06-kubernetes-k8s-paas-03k8s.md].

Sources

^[400-devops-06-kubernetes-k8s-paas-03k8s.md]