Live
Handling Faster Code, Token Spikes, and Agent Guardrails in LLM ProductionAdding Cloudflare Web Search to Agents SDK: Direct Web Queries for Your Durable ObjectsWorkers Observability Events via MCP: Real‑Time Issue Delivery to WebhooksMultilingual Agent Kit Adds Go, Java, Kotlin, and TypeScript SupportScaling AI Agent Swarms: Architecture and Ops Implications for EngineersAnonymous authentication for organization‑level Dependabot registries: practical impactCloudflare Queues add immutable jurisdiction controls for data residencyOpen AI Factory Architecture: NVIDIA’s MGX 1.2 Rack Design and New DSX Tooling Arrive at OCPHandling Faster Code, Token Spikes, and Agent Guardrails in LLM ProductionAdding Cloudflare Web Search to Agents SDK: Direct Web Queries for Your Durable ObjectsWorkers Observability Events via MCP: Real‑Time Issue Delivery to WebhooksMultilingual Agent Kit Adds Go, Java, Kotlin, and TypeScript SupportScaling AI Agent Swarms: Architecture and Ops Implications for EngineersAnonymous authentication for organization‑level Dependabot registries: practical impactCloudflare Queues add immutable jurisdiction controls for data residencyOpen AI Factory Architecture: NVIDIA’s MGX 1.2 Rack Design and New DSX Tooling Arrive at OCP
Kubernetes

kubectl Complete Command Reference: Pods, Deployments and Services

Overview

This tutorial provides a comprehensive, hands-on reference for kubectl — the command-line tool for interacting with Kubernetes clusters. You will learn how to create, inspect, update, and delete Pods, Deployments, and Services using real commands you can run immediately in any Kubernetes environment.

  • Manage Pod lifecycle from creation to termination
  • Deploy and scale applications using Deployments
  • Expose workloads internally and externally with Services
  • Interpret resource output and troubleshoot common issues

Prerequisites: Basic Linux CLI experience, a running Kubernetes cluster (minikube, kind, or any cloud-managed cluster), and kubectl installed and configured with a valid kubeconfig.

Why this matters for CKA: The Certified Kubernetes Administrator exam is entirely hands-on. You will be given a live cluster and timed tasks. Mastery of kubectl commands — especially imperative ones — is the fastest path to passing. This guide mirrors the exact task types found in the exam environment.

Getting Started

Verify your environment is ready before proceeding. Every command in this guide assumes kubectl is configured and pointing at a valid cluster context.

# Check kubectl version
kubectl version --client

# View current cluster context
kubectl config current-context

# List all available contexts
kubectl config get-contexts

# Switch context if needed
kubectl config use-context minikube

# Confirm cluster nodes are healthy
kubectl get nodes -o wide

Set a default namespace for your session to avoid appending -n <namespace> to every command during practice or an exam task:

# Set a default namespace for the current context
kubectl config set-context --current --namespace=default

# Verify the namespace is set
kubectl config view --minify | grep namespace

Working with Pods

A Pod is the smallest deployable unit in Kubernetes. It wraps one or more containers and shares network and storage resources. Understanding Pod management is foundational to everything else in Kubernetes.

Creating Pods imperatively is the fastest method during the CKA exam. Use --dry-run=client -o yaml to generate manifests without applying them — a critical exam technique.

# Run a pod imperatively
kubectl run nginx-pod --image=nginx:1.25 --port=80

# Generate a pod manifest without creating the resource
kubectl run nginx-pod --image=nginx:1.25 --port=80 \
  --dry-run=client -o yaml > nginx-pod.yaml

# Apply the manifest
kubectl apply -f nginx-pod.yaml

# List pods with additional detail
kubectl get pods -o wide

# Describe a pod for events and resource details
kubectl describe pod nginx-pod

# View logs from a running pod
kubectl logs nginx-pod

# Stream live logs
kubectl logs -f nginx-pod

# Execute a command inside a running pod
kubectl exec -it nginx-pod -- /bin/bash

# Delete a pod immediately (no graceful shutdown)
kubectl delete pod nginx-pod --grace-period=0 --force

Common pitfall: Using kubectl run in older Kubernetes versions created a Deployment by default. Since Kubernetes 1.18+, kubectl run creates a bare Pod. Know which version your exam cluster is running.

Use labels and selectors to filter and group resources efficiently:

# Add a label to an existing pod
kubectl label pod nginx-pod env=production

# Filter pods by label
kubectl get pods -l env=production

# Remove a label
kubectl label pod nginx-pod env-

Managing Deployments and Services

A Deployment manages a ReplicaSet which in turn manages Pods. It provides declarative updates, rollback capability, and self-healing. For any stateless workload, a Deployment is the correct abstraction.

# Create a deployment imperatively
kubectl create deployment web-app --image=nginx:1.25 --replicas=3

# Generate deployment manifest
kubectl create deployment web-app --image=nginx:1.25 --replicas=3 \
  --dry-run=client -o yaml > web-app-deployment.yaml

# Apply from manifest
kubectl apply -f web-app-deployment.yaml

# View deployments
kubectl get deployments

# Describe a deployment
kubectl describe deployment web-app

# Scale a deployment
kubectl scale deployment web-app --replicas=5

# Update the container image (triggers a rolling update)
kubectl set image deployment/web-app nginx=nginx:1.26

# Check rollout status
kubectl rollout status deployment/web-app

# View rollout history
kubectl rollout history deployment/web-app

# Roll back to previous revision
kubectl rollout undo deployment/web-app

# Roll back to a specific revision
kubectl rollout undo deployment/web-app --to-revision=1

A Service provides a stable network endpoint for a set of Pods. Kubernetes offers several Service types: ClusterIP (internal only), NodePort (exposes on node IP), and LoadBalancer (provisions external load balancer).

# Expose a deployment as a ClusterIP service
kubectl expose deployment web-app --port=80 --target-port=80 \
  --name=web-app-svc --type=ClusterIP

# Expose as NodePort
kubectl expose deployment web-app --port=80 --target-port=80 \
  --name=web-app-nodeport --type=NodePort

# Create a service imperatively using create
kubectl create service clusterip web-app-svc \
  --tcp=80:80 --dry-run=client -o yaml

# List services
kubectl get services

# Describe a service (check endpoints and selector)
kubectl describe service web-app-svc

# Check service endpoints (are pods actually selected?)
kubectl get endpoints web-app-svc

# Port-forward to test a service locally
kubectl port-forward service/web-app-svc 8080:80

Best practice: Always verify Endpoints after creating a Service. If the Endpoints object shows <none>, your Service selector does not match any Pod labels. This is one of the most common misconfigurations in the exam.

# Quick label mismatch diagnosis workflow
kubectl get pods --show-labels
kubectl describe service web-app-svc | grep Selector

# Patch a service selector if needed
kubectl patch service web-app-svc \
  -p '{"spec":{"selector":{"app":"web-app"}}}'

Exam Tips for Certified Kubernetes Administrator (CKA)

The CKA exam allocates approximately 25% of its score to workloads and scheduling, which directly covers Pods, Deployments, and Services. Speed and accuracy with kubectl are non-negotiable.

  • Use imperative commands first: Always reach for kubectl create, kubectl run, and kubectl expose before writing YAML from scratch. Save time by generating manifests with --dry-run=client -o yaml.
  • Set aliases immediately: At exam start, set alias k=kubectl and enable bash completion with source <(kubectl completion bash).
  • Use kubectl explain: You cannot access external documentation during the exam, but you can use kubectl explain pod.spec.containers to browse the API schema inline.
  • Namespace awareness: Many exam tasks specify a namespace. Always confirm with -n <namespace> or set it in your context first.
  • Know rollout commands cold: Rolling updates and rollbacks are frequent exam tasks. Practice kubectl rollout status, history, and undo until they are muscle memory.

Quick reference commands for exam day:

# Alias and completion setup (run at exam start)
alias k=kubectl
complete -F __start_kubectl k
source <(kubectl completion bash)

# Fast pod debugging sequence
k get pods -o wide
k describe pod <pod-name>
k logs <pod-name> --previous
k exec -it <pod-name> -- /bin/sh

# Inline API documentation
kubectl explain deployment.spec.strategy
kubectl explain service.spec.type

# Get all resources in a namespace at once
kubectl get all -n <namespace>

# Output as YAML for inspection or editing
kubectl get deployment web-app -o yaml

# Edit a live resource in-place
kubectl edit deployment web-app

Summary

You have now covered the complete essential kubectl workflow for Pods, Deployments, and Services — the three most operationally critical resource types in Kubernetes.

  • Use imperative commands with --dry-run=client -o yaml to generate manifests quickly and accurately
  • Deployments manage rollouts, scaling, and self-healing for stateless applications
  • Services provide stable networking — always verify Endpoints after creation
  • Troubleshoot with describe, logs, and exec in that order
  • Rolling update and rollback commands are high-value exam targets — practice them daily

Next steps: Extend your knowledge to ConfigMaps, Secrets, and resource limits, then move into cluster-level topics such as RBAC, network policies, and persistent storage. Each of these builds directly on the Pod and Deployment fundamentals covered here.

For a complete CKA study path including practice labs and mock exams, visit the CloudNinjas CKA Certification Guide.