⌂ Home

kubectl Essentials

Interactive guide to the everyday create, inspect, expose, scale, debug, and cleanup workflow with kubectl.

kubectl is not just a collection of commands. It supports a repeatable operational loop: create, inspect, expose, change, debug, and clean up.

Core Model

Understand the Concept First

Imperative creation

Fast for learning, testing, and one-off actions.

Inspection is central

get, describe, logs, and events reveal what the cluster is really doing.

Declarative bridge

dry-run and YAML output help users move from imperative commands to versioned manifests.

Lifecycle Flow

kubectl Command Execution Flow

kubectl Command Execution: kubeconfig → API server → etcd kubectl kubectl get pods CLI parses command, reads kubeconfig kubeconfig ~/.kube/config Contains: cluster URL, user certs, context kube-apiserver Authentication, Authorization, Admission etcd Persistent storage Cluster state, resource definitions Response flows back to kubectl Context Switching: Clusters, Users, Namespaces Clusters production https://k8s-prod :6443 staging https://k8s-stg :6443 kubectl config get-clusters Users admin Client cert Full access developer Token auth Limited access kubectl config get-users Namespaces default User workloads kube-system System pods myapp App namespace kubectl get namespaces Context = Cluster + User + Namespace kubectl config use-context prod-admin-default Switches to production cluster, admin user, default namespace Imperative vs Declarative Comparison Imperative Characteristics: • Direct commands tell cluster what to do • Fast for learning and testing • Not version-controlled • Hard to replicate Examples: kubectl create deployment web --image=nginx kubectl scale deployment web --replicas=3 Declarative Characteristics: • YAML manifests describe desired state • Version-controlled, repeatable • Git-friendly, team-ready • Production best practice Examples: kubectl apply -f deployment.yaml kubectl apply -f ./manifests/ Use dry-run to bridge: kubectl create deployment web --image=nginx --dry-run=client -o yaml > web.yaml
Most kubectl fluency comes from understanding which command category to reach for at each stage of that operator loop.
YAML and Commands

Examples You Can Recognize Quickly

Core Commands
kubectl create deployment myapp1 --image=docker.io/openshift/hello-openshift
kubectl get pods
kubectl describe deployment myapp1
kubectl scale deployment myapp1 --replicas=3
Generate YAML
kubectl create deployment myhttpd --image=docker.io/httpd --dry-run=client -o yaml > myapp1.yaml
Decision Guide

Imperative vs Declarative Use

Mode Strength Typical use
Imperative Fast and direct Learning, quick tests, ad hoc changes
Declarative Repeatable and versionable Team workflows, Git-based operations, long-term management
Strong operators usually know both styles and switch between them intentionally.
Use It Well

Practice and Real-World Thinking

Fast lab work

Use imperative commands to move quickly while learning.

Better debugging

Use describe, logs, and events together to form a full picture.

Manifest generation

Use dry-run YAML output as a starting point for cleaner manifests.