kubectl
The command-line tool for talking to a Kubernetes cluster's API server: creating, reading, changing and deleting objects.
In more detail
Every kubectl command becomes one or more API requests made with the credentials in your kubeconfig. The general shape is kubectl, a verb such as get or apply, a type, and a name. It warns when its version is more than one minor release away from the server.
Examples
kubectl get podskubectl versionkubectl apply -f pod.jsonkubectl label namespace payments pod-security.kubernetes.io/enforce=restrictedkubectl create role order-reader --verb=get --verb=list --resource=pods --dry-run=client -o yamlThe course uses kubectl create role with --dry-run=client -o yaml, so the tool prints the Role it would create as YAML without touching a cluster.Related terms
- API server — The Kubernetes control plane component that serves the Kubernetes API; every read and change to the cluster goes through it.
- kubectl exec — The kubectl command that runs a command, such as a shell, inside a running container.
- Kubernetes — An open-source system that runs and manages containers across a cluster of machines.
- push model — An arrangement where a central machine sends changes out to the hosts when someone runs it, as Ansible does.
- kubectl apply — The kubectl command that creates or updates Kubernetes objects to match the manifests you give it.
- kubeconfig — The file that tells kubectl which clusters exist, which credentials to use, and which pairing of the two is currently selected.
- kubectl get — The kubectl command that lists objects of one or more types, or shows one object, in a table or another output format.
- manifest — A file that describes a set of things in a structured format, such as the resources a system should create or the files a package should contain.
- Kubernetes namespace — A named area inside a cluster that keeps object names apart and groups them for permissions, quotas and policies.
- Role — A namespaced RBAC object listing which verbs are allowed on which resources inside one namespace.
- dry run — Sending a real request in a check-only mode, so the system reports whether it would succeed without actually making the change.
Related guides
- How to prepare for the CKA and CKAD exams, with labs
- CKA vs CKAD: which Kubernetes exam should you take first?
Taught in
- Serverless And Container Patterns: Where The Limits Bite — AWS Certified Solutions Architect – Associate (SAA-C03) Exam Prep
- A Hotfix At 3 A.M.: Who Wins At 3:05? — Certified GitOps Associate (CGOA) Exam Prep
- Staging Is Gone: Desired State, Declarations And The State Store — Certified GitOps Associate (CGOA) Exam Prep
- Three Edits At 2 A.M.: Drift And Reconciliation — Certified GitOps Associate (CGOA) Exam Prep
- Sixteen Pods, Room For Twelve: The System, Feedback And Continuous — Certified GitOps Associate (CGOA) Exam Prep
- Two Ways Back From 2.5: Rollback The GitOps Way — Certified GitOps Associate (CGOA) Exam Prep
- Terminology Sprint: One Incident, Nine Terms — Certified GitOps Associate (CGOA) Exam Prep
- Seven Steps Called GitOps: The Declarative Principle — Certified GitOps Associate (CGOA) Exam Prep
- Twelve Keys To Production: Pulled Automatically — Certified GitOps Associate (CGOA) Exam Prep
- Principles Sprint: Six Setups, One Question — Certified GitOps Associate (CGOA) Exam Prep
- Two Clicks Nobody Wrote Down: Configuration And Infrastructure As Code — Certified GitOps Associate (CGOA) Exam Prep
- What Does CI Still Do? CI, CD And Where GitOps Starts — Certified GitOps Associate (CGOA) Exam Prep
- Related Practices Sprint: One Change, Five Practices — Certified GitOps Associate (CGOA) Exam Prep
- Friday, Four Fifty: Progressive Delivery — Certified GitOps Associate (CGOA) Exam Prep
- Three Minutes Of Waiting: Pull Versus Event-Driven — Certified GitOps Associate (CGOA) Exam Prep
- Three Regions By Spring: GitOps Architecture — Certified GitOps Associate (CGOA) Exam Prep
- Three Teams, Three Formats: Manifests And Packaging — Certified GitOps Associate (CGOA) Exam Prep
- Tooling Sprint: The CTO's Shopping List — Certified GitOps Associate (CGOA) Exam Prep
- Forty-Six Of Sixty: The Mock And What It Tells You — Certified GitOps Associate (CGOA) Exam Prep
- The Evening Before: Final Review — Certified GitOps Associate (CGOA) Exam Prep
- DORA Metrics: Measuring Your Pipeline — Continuous Integration & Continuous Delivery Pipelines
- Artifact Promotion: Staging to Production — Continuous Integration & Continuous Delivery Pipelines
- The Push Model vs. The Pull Model — Continuous Integration & Continuous Delivery Pipelines
- Rolling Back Blue-Green — Continuous Integration & Continuous Delivery Pipelines
- A Node Goes NotReady Forty Minutes In — Certified Kubernetes Administrator (CKA) Exam Prep
- Spend Two Hours Like A Points Table — Certified Kubernetes Administrator (CKA) Exam Prep
- Generators Write The YAML, You Decide — Certified Kubernetes Administrator (CKA) Exam Prep
- Contexts, Namespaces And One-Line Answers — Certified Kubernetes Administrator (CKA) Exam Prep
- Node NotReady: Kubelet, Runtime And Certificates — Certified Kubernetes Administrator (CKA) Exam Prep
- When A Control Plane Pod Breaks — Certified Kubernetes Administrator (CKA) Exam Prep
- Usage, Requests And The Pod That Will Not Fit — Certified Kubernetes Administrator (CKA) Exam Prep
- What A Container Said Before It Died — Certified Kubernetes Administrator (CKA) Exam Prep
- Running, And Still Down — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Two Hours, Twenty Tasks: Exam Strategy — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Container Images The Exam Way — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Choose The Right Workload Resource — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Sidecars And Init Containers — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Persistent And Ephemeral Volumes — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Jobs And CronJobs That Behave — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Design And Build: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Rolling Updates And Rollbacks — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Blue/Green With Labels And A Service — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Canary Releases From Replica Counts — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Helm: Install, Upgrade And Roll Back — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Kustomize Bases, Overlays And Patches — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Deployment: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- API Deprecations And Migrations — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Probes And Health Checks — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Monitoring With The Built-in CLI — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Container Logs — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Debugging Applications In Kubernetes — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Observability: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- ConfigMaps And Secrets — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Requests, Limits And Quotas — Certified Kubernetes Application Developer (CKAD) Exam Prep
- ServiceAccounts And Tokens — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Authentication, Authorisation And Admission — Certified Kubernetes Application Developer (CKAD) Exam Prep
- SecurityContexts And Capabilities — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Custom Resources And Operators — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Configuration And Security: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Services And Empty Endpoints — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Services And Networking: Timed Drill And Checkpoint — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Mock Exam: Sixteen Tasks Against The Clock — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Final Review: Where Your Marks Are At Risk — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Six Seconds, Every Secret — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Two Hours, Sixteen Tasks: A CKS Plan — Certified Kubernetes Security Specialist (CKS) Exam Prep
- The Metadata Endpoint And The Kubelet's Front Door — Certified Kubernetes Security Specialist (CKS) Exam Prep
- kube-bench: Ten Failures On A Fresh Cluster — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Ingress TLS: When The Padlock Lies — Certified Kubernetes Security Specialist (CKS) Exam Prep
- RBAC: Find The Path To Cluster Admin — Certified Kubernetes Security Specialist (CKS) Exam Prep
- ServiceAccounts: Take Back The Key — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Upgrading For CVEs: Read The Feed, Then Patch — Certified Kubernetes Security Specialist (CKS) Exam Prep
- The Host Footprint: Six Doors On A Worker — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Seccomp: Which Syscalls A Container May Make — Certified Kubernetes Security Specialist (CKS) Exam Prep
- AppArmor: The Guard Docker Desktop Does Not Have — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Pod Security Admission: Created, Never Started — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Encryption At Rest: What etcd Really Holds — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Secrets In Use: Leaks Through Env, Specs And Images — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Allowed Registries: Admission That Refuses Images — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Audit Policy: Choosing What The Cluster Remembers — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Investigating An Attack: One Timeline, Two Logs — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Immutable Containers: Read-Only At Runtime — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Mock Exam: Seventeen Security Tasks Against The Clock — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Final Review: The Cluster You Would Defend — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Container Hardening: Distroless & Rootless — Cloud Security & DevSecOps Engineering
- Kubernetes Pod Security Standards: Baseline & Restricted — Cloud Security & DevSecOps Engineering
- Runtime Anomaly Detection with Falco & eBPF — Cloud Security & DevSecOps Engineering
- Securing the Kubernetes Control Plane & Node Components — Cloud Security & DevSecOps Engineering
- CloudTrail Logging, Integrity Validation & Athena — Cloud Security & DevSecOps Engineering
- Security Frameworks: NIST CSF 2.0, ISO 27001 & CIS — Cybersecurity Fundamentals, GRC & Cryptography
- GKE Clusters And A First Deploy — Google Cloud Associate Cloud Engineer Exam Prep
- Tooling: Infrastructure As Code And AI Assistants — Google Cloud Associate Cloud Engineer Exam Prep
- Running GKE — Google Cloud Associate Cloud Engineer Exam Prep
- The gcloud And Product-Name Sprint — Google Cloud Associate Cloud Engineer Exam Prep
- One Command, Six Programs — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Pin It, Lint It, Prove It: Images And Runtimes — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Who Owns The Symptom: Control Plane And Nodes — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Same Name, Wrong Namespace: Objects, Namespaces And Labels — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Five Jobs, Five Workloads — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- A Name That Outlives Its Pods: Services And DNS — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Pending All Saturday: How The Scheduler Places Pods — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Wrong Cluster, Wrong Version: Contexts, Upgrades And Skew — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Not The Admin Certificate: RBAC And ServiceAccounts — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Fundamentals Sprint: Four Tickets Before The Doors Open — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Who May Call Payments: Pod Networking And Policy — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Not As Root, Not In Plain Sight: Pod Security And Secrets — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- The Status Tells You Where To Look: Troubleshooting Pods — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Bookings That Survive The Pod: Volumes And Claims — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Six Times The Traffic: Autoscaling Pods And Nodes — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Orchestration Sprint: Four Fixes, No Walls Removed — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Two Versions Of The Truth: GitOps, Helm And Kustomize — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Always A Way Back: Rolling, Blue/Green And Canary — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Running, Green And Still Broken: Debugging Applications — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Delivery Sprint: Friday At Five — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- The Image Nobody Tested: Cloud Native Principles — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Slow, Or Broken? Metrics, Logs And Traces — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Architecture Sprint: The Refunds Review — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- Forty Four Of Sixty: The Full Mock, And How To Read It — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- The Festival, End To End: Final Review — Kubernetes and Cloud Native Associate (KCNA) Exam Prep
- One Leaked Kubeconfig: How Far Does It Go? — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Seven Findings, Two Owners: The 4Cs And Shared Responsibility — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Same Rule, Two Kinds: Controls And Frameworks — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- How Thick Is The Wall? Isolation Techniques — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Overview Sprint: Four Findings Before The Auditor — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Eleven Months Of Yes: The API Server — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Copied From A Blog Post: The Kubelet — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- A Pod That Mounts The Node: Runtime, Pods And Storage — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- A Copy Of The Backup: etcd — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Port 30080 On Every Node: kube-proxy, Networking And Clients — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Component Sprint: The Reference Build — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Created, But Never Running: Pod Security Admission — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- There Is No Users Table: Authentication — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Read-Only, Except Secrets: RBAC In Depth — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Encoded Is Not Hidden: Secrets — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- One Dash Too Many: Segmentation With Network Policy — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Fundamentals Sprint: Four Findings, Eight Questions — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Draw The Boundaries: Trust And Data Flow — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- What Outlives The Fix: Persistence And Privilege Escalation — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- The Report That Ate The Node: Denial Of Service And Malicious Code — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- One Pod Away: Network Attackers And Sensitive Data — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Threat Model Sprint: Name It, Then Stop It — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Who Built This Image? Supply Chain And Registries — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Four Alerts, One Incident: Observability And The Mesh — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- A Cluster's First Birthday: PKI And Connectivity — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Forty Minutes Of Yes: Admission Control — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Platform Sprint: Evidence, Order, Proof — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Audit Day: Final Review — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- From Docker To Desired State — Kubernetes: Production-Grade Container Orchestration
- Control Plane: etcd, API Server, Scheduler, Controllers — Kubernetes: Production-Grade Container Orchestration
- Worker Nodes: kubelet, Runtime, CNI And kube-proxy — Kubernetes: Production-Grade Container Orchestration
- Bootstrap A Local Cluster And Check Your Context — Kubernetes: Production-Grade Container Orchestration
- Namespaces, Labels And Declarative Manifests — Kubernetes: Production-Grade Container Orchestration
- Troubleshooting: describe, Events And A First Smoke Test — Kubernetes: Production-Grade Container Orchestration
- Pods, Init Containers And Sidecars — Kubernetes: Production-Grade Container Orchestration
- Troubleshooting: NotReady Nodes And kubelet Logs — Kubernetes: Production-Grade Container Orchestration
- Least Privilege In IAM And RBAC — Application Security & Threat Modeling for Engineers
References
Certification courses
- AWS Solutions Architect Associate course and practice exam: SAA-C03
- CGOA course and practice exam: Certified GitOps Associate
- CKA course and practice exam: Certified Kubernetes Administrator
- CKAD course and practice exam: Certified Kubernetes Application Developer
- CKS course and practice exam: Certified Kubernetes Security Specialist
- Google Associate Cloud Engineer course and practice exam: Google Cloud certification
- KCNA course and practice exam: Kubernetes and Cloud Native Associate
- KCSA course and practice exam: Kubernetes and Cloud Native Security Associate