Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
CLI K8s Basics Kubernetes Kubernetes: From Zero to Production Module 2 - Cluster Architecture

kubectl Basics - Every Command You Need

Reviewed & accurate
AI Summary

What You Will Learn

Beginner

  • All essential kubectl commands
  • How to inspect and manage K8s resources
  • Common flags and patterns

Essential Commands

CommandWhat it does
kubectl get podsList Pods
kubectl get svcList Services
kubectl get deployList Deployments
kubectl describe pod NAMEDetail about a Pod
kubectl logs POD_NAMEView Pod logs
kubectl exec -it POD -- bashShell into a Pod
kubectl apply -f file.yamlCreate/update from YAML
kubectl delete pod NAMEDelete a Pod
kubectl port-forward POD 8080:80Forward local port to Pod
kubectl get allList everything

Useful Flags

Terminalbash
# Wide output (more columns)
kubectl get pods -o wide

# All namespaces
kubectl get pods --all-namespaces

# YAML output
kubectl get pod my-app -o yaml

# Watch (live updates)
kubectl get pods -w

# Labels
kubectl get pods --show-labels
kubectl get pods -l app=my-app

Common Patterns

Terminalbash
# Get a shell in a Pod
kubectl exec -it my-pod -- bash

# View logs (follow)
kubectl logs -f my-pod

# Port forward to access locally
kubectl port-forward svc/my-service 8080:80

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

# Rollout status
kubectl rollout status deployment/my-app

Practical Exercise

Run: kubectl get pods
Run: kubectl get pods -o wide
Run: kubectl describe pod
Run: kubectl logs
Run: kubectl get all --all-namespaces

Key Takeaways

  • get: list resources. describe: detailed info.
  • logs: view output. exec: shell into Pod.
  • apply -f: create/update from YAML.
  • port-forward: access Pod locally.
  • -o wide: more columns. -w: watch. --all-namespaces: everything.
Previously: Lesson 09 covered namespaces.
Today: You learned: The 20 kubectl commands you will use daily.
Next: Lesson 11 covers YAML.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments