Mastering Kubernetes Core Resource Management: 3 Declarative Methods Explained
This guide walks through three fundamental ways to manage Kubernetes core resources—imperative CLI commands, declarative manifest files, and GUI tools—covering namespaces, deployments, services, scaling, and cleanup with practical kubectl examples.
1. Three basic methods to manage Kubernetes core resources
Imperative (CLI) method: use kubectl commands
Declarative method: use manifest files
GUI method: use web UI
2. Imperative resource management
The imperative approach performs create, read, update, and delete (CRUD) operations directly via kubectl.
2.1 Manage Namespace resources
2.1.1 View namespaces kubectl get namespaces 2.1.2 View resources in a namespace kubectl get all -n default 2.1.3 Create a namespace kubectl create namespace app 2.1.4 Delete a namespace
kubectl delete ns app2.2 Manage Deployment resources
2.2.1 Create a deployment
kubectl create deployment nginx-dp --image=harbor.od.com/public/nginx:v1.7.9 -n kube-public2.2.2 View the deployment kubectl get deployment -n kube-public 2.2.3 View pods created by the deployment kubectl get pod -n kube-public -o wide 2.2.4 Exec into a pod
kubectl exec -it nginx-dp-<span>pod-id</span> -n kube-public -- bash2.2.5 Delete a pod (forces restart)
kubectl delete pod nginx-dp-<span>pod-id</span> -n kube-public2.2.6 Delete the deployment
kubectl delete deployment nginx-dp -n kube-public2.3 Manage Service resources
2.3.1 Create a service by exposing the deployment
kubectl expose deployment nginx-dp --port=80 -n kube-public2.3.2 View the service details kubectl describe svc nginx-dp -n kube-public 2.3.3 View IPVS proxy table and scale the deployment
ipvsadm -Ln kubectl scale deployment nginx-dp --replicas=2 -n kube-public2.4 Summary of the imperative method
Kubernetes clusters are managed through API‑server calls.
kubectl is the official CLI tool for communicating with the API server.
The imperative method satisfies most CRUD needs but commands can be verbose and harder to remember.
3. Declarative resource management
The declarative approach relies on YAML or JSON manifests that describe the desired state of resources.
3.1 View resource manifests
kubectl get pod nginx-dp-... -o yaml -n kube-public3.2 Explain manifest fields
kubectl explain service.metadata3.3 Create resources from a manifest
kubectl create -f nginx-ds-svc.yaml3.4 Apply changes to a manifest
Offline edit the YAML file then apply: kubectl apply -f nginx-ds-svc.yaml Online edit with kubectl edit:
kubectl edit svc nginx-ds3.5 Delete resources
kubectl delete svc nginx-ds kubectl delete -f nginx-ds-svc.yaml3.6 Summary of the declarative method
Manifests define resources and are applied with kubectl.
Changes are version‑controlled, reproducible, and easier to audit.
Typical workflow uses create/apply/delete with -f files.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
