CFN Cloud
Cloud Future New Life
en zh
2025-10-06 · 0 views

Declarative Object Configs

Manage resources with YAML and a reviewable change workflow.

Declarative config means you describe the desired state in files and manage everything through kubectl apply.

Why it works

  • Changes are reviewable in git
  • Rollbacks are simple by reapplying history
  • Reapplying the same file is safe

Multi-object example

apiVersion: v1
kind: Namespace
metadata:
  name: demo
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: nginx:1.25

Common flow

kubectl apply -f app.yaml
kubectl diff -f app.yaml
kubectl delete -f app.yaml

Tips

  • Standardize labels and selectors
  • Run kubectl diff before apply

Practical notes

  • Start with a quick inventory: kubectl get nodes, kubectl get pods -A, and kubectl get events -A.
  • Compare desired vs. observed state; kubectl describe usually explains drift or failed controllers.
  • Keep names, labels, and selectors consistent so Services and controllers can find Pods.

Quick checklist

  • The resource matches the intent you described in YAML.
  • Namespaces, RBAC, and images are correct for the target environment.
  • Health checks and logs are in place before promotion.

References