K8s CKA Certificate 2 — YAML Basics

Tony
8 min readJul 24, 2024

In my last CKA article, I introduced the components on K8s management nodes and worker nodes, as well as the rich resource objects in K8s. These resource objects are like a toolkit provided by K8s, meeting our various requirements for deploying applications and managing clusters.

There are two ways to interact with these resource objects: one is using the kubectl command, and the other is using YAML files. These correspond to the imperative and declarative operation modes, respectively.

Imperative vs. Declarative

  • Imperative Operations: These are like giving direct commands, such as instructing K8s to create or delete a specific resource object. This method is straightforward but can lead to confusion if multiple people are making changes simultaneously or if frequent modifications are needed, as it does not record the entire sequence of operations.
  • Declarative Operations: In this approach, you describe the desired state of a resource object to K8s. By using the kubectl apply command, K8s reads the configuration file and automatically changes the current state of the resource object to match the desired state. The advantage of this method is that you can always refer to the declaration files to clearly understand the desired state of the resource objects and manage them by modifying the…

--

--