Kubernetes
02 / 04

Core Concepts & kubectl

Core Concepts & kubectl

Key Objects

  • Pod — smallest deployable unit; one or more containers sharing network/storage

  • Deployment — manages replicated Pods with rolling updates and rollback

  • Service — stable network endpoint for a set of Pods (ClusterIP/NodePort/LoadBalancer)

  • ConfigMap — non-sensitive config data injected as env vars or files

  • Secret — sensitive data (base64 encoded, not encrypted by default — use Sealed Secrets or external secret managers)

  • Ingress — HTTP routing rules into cluster Services (requires an Ingress controller)

  • Namespace — virtual cluster for resource isolation (default, kube-system, etc.)

  • PersistentVolume / PVC — storage abstraction; PVC claims storage from a PV

kubectl Essentials

# Cluster info
kubectl cluster-info
kubectl get nodes
kubectl config current-context
kubectl config use-context my-cluster

# Namespaces
kubectl get namespaces
kubectl create namespace staging
kubectl -n staging get pods        # operate in a specific namespace
kubectl config set-context --current --namespace=staging  # set default ns

# Pods
kubectl get pods                   # list pods
kubectl get pods -o wide           # with IP and node
kubectl get pods --all-namespaces  # all namespaces
kubectl describe pod my-pod        # detailed info + events
kubectl logs my-pod                # view logs
kubectl logs my-pod -f             # follow logs
kubectl logs my-pod -c sidecar     # specific container
kubectl exec -it my-pod -- bash    # interactive shell
kubectl exec my-pod -- env         # run command
kubectl delete pod my-pod          # delete (will be recreated if in Deployment)

# Deployments
kubectl get deployments
kubectl describe deployment my-app
kubectl scale deployment my-app --replicas=5
kubectl rollout status deployment my-app
kubectl rollout history deployment my-app
kubectl rollout undo deployment my-app          # roll back
kubectl rollout undo deployment my-app --to-revision=2

# Apply / delete manifests
kubectl apply -f deployment.yaml
kubectl apply -f ./k8s/                # apply all files in directory
kubectl delete -f deployment.yaml
kubectl diff -f deployment.yaml        # see what would change

# Port forwarding (local access to pod/service)
kubectl port-forward pod/my-pod 8080:3000
kubectl port-forward service/my-service 8080:80

# Copy files
kubectl cp my-pod:/app/logs ./local-logs
kubectl cp ./file.txt my-pod:/tmp/

# Get resource as YAML
kubectl get deployment my-app -o yaml
kubectl get all -l app=my-app

Labels & Selectors

# Filter by label
kubectl get pods -l app=my-app
kubectl get pods -l env=prod,tier=frontend
kubectl get pods -l 'env in (prod,staging)'
kubectl get pods -l '!test'            # no 'test' label

# Label resources
kubectl label pod my-pod env=prod
kubectl label pod my-pod env-          # remove label
kubectl annotate pod my-pod team=backend

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free