kubectl Commands Essentials
Master essential `kubectl` commands for interacting with your Kubernetes cluster and managing resources.
kubectl Commands Essentials is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet Your Kubernetes CLI
Welcome to kubectl Commands Essentials! In this lesson, you'll learn how to use kubectl, the command-line tool that lets you talk to your Kubernetes cluster.
Think of kubectl as your remote control for managing applications, inspecting cluster resources, and debugging issues directly from your terminal.

How kubectl Connects
Before kubectl can do anything, it needs to know which Kubernetes cluster to talk to. This is handled by a kubeconfig file (usually ~/.kube/config).
- It contains connection details like cluster IP, authentication info.
kubectlautomatically uses the default context in this file.- You can switch contexts to manage multiple clusters.
Get Cluster Resources
The kubectl get command is fundamental. It allows you to list various resources in your cluster, such as pods, nodes, deployments, and services.
It's your window into seeing what's currently running or configured.
kubectl get pods
kubectl get nodes
kubectl get servicesDetailed Resource Info
While get gives you a summary, kubectl describe provides a wealth of detailed information about a specific resource. This includes events, status, configurations, and more, which is crucial for debugging.
kubectl describe pod my-app-pod-xyz
kubectl describe node my-node-nameApplying Configuration Files
You define Kubernetes resources using YAML files. The kubectl apply -f command is used to create or update resources based on these files. It's idempotent, meaning you can run it multiple times safely.
Here's a simple Pod definition:
apiVersion: v1
kind: Pod
metadata:
name: my-first-pod
spec:
containers:
- name: web
image: nginx:latest
ports:
- containerPort: 80Creating Resources with Apply
To create the Pod defined in the previous scene, you would save it as a .yaml file (e.g., pod.yaml) and then use kubectl apply.
This command tells Kubernetes to make sure the state described in your YAML matches the cluster's actual state.
kubectl apply -f pod.yaml
# After applying, verify:
kubectl get pod my-first-podViewing Container Logs
When troubleshooting, checking container logs is often the first step. The kubectl logs command fetches logs from a specific container within a Pod.
Use -f to follow logs in real-time, just like tail -f.
kubectl logs my-first-pod
kubectl logs -f my-first-podExecuting Commands in Pods
Need to run a command inside a running container for debugging? kubectl exec lets you do just that. You can even open an interactive shell.
-ifor interactive-tfor pseudo-TTY--separateskubectloptions from the command to run
kubectl exec -it my-first-pod -- bash
# Or run a single command:
kubectl exec my-first-pod -- ls /appDeleting Resources
To remove resources from your cluster, use the kubectl delete command. You can delete by type and name, or by specifying the YAML file used to create it.
Be careful with delete, as it's a permanent action!
kubectl delete pod my-first-pod
kubectl delete -f pod.yamlkubectl Command Check
Which kubectl command would you use to get detailed information about a specific node named worker-node-1?
Recap: Your kubectl Toolkit
Great job! You've mastered the essential kubectl commands:
get: List resources.describe: Get detailed info.apply -f: Create/update resources from YAML.logs: View container output.exec: Run commands inside containers.delete: Remove resources.
These commands are your daily companions for interacting with Kubernetes!
Frequently asked questions
Is the “kubectl Commands Essentials” lesson free?
Yes — the full text of “kubectl Commands Essentials” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “kubectl Commands Essentials”?
Master essential `kubectl` commands for interacting with your Kubernetes cluster and managing resources. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Docker & DevOps Fundamentals?
No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “kubectl Commands Essentials” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Docker & DevOps Fundamentals lesson?
Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Kubernetes Architecture
- Pods: The Smallest Units
- kubectl Commands Essentials
- Namespaces and Labels for Organization