Previous slide Next slide Toggle fullscreen Open presenter view
Kubernetes Essentials
by Konrad Mosoล
Basic Commands
kubectl get, describe, exec, logs, apply, delete
Connecting to a pod for the first time
Using kubectl port-forward for debugging
Managing contexts and namespaces
Contexts & Namespaces
kubectl config get-contexts
kubectl config use-context <context>
kubectl get pods -n <namespace>
Crucial for multi-cluster and multi-team environments
kubectl config & use-context
Manage kubeconfig files and switch between clusters.
kubectl config get-contexts
kubectl config use-context <context-name>
kubectl config current-context
Tips:
Config from environment variable
Use KUBECONFIG environment variable to load different config.
export KUBECONFIG=~/.kube/config-another
kubectl get pods
kubectl get
Used to list and inspect resources quickly.
kubectl get pods
kubectl get svc
kubectl get deployments
Common flags:
-n <namespace> โ specify namespace
-o wide โ show more info (IP, node, etc.)
-o yaml or -o json โ full resource output
kubectl describe
Detailed info about a resource (events, specs, status).
kubectl describe pod <pod-name>
kubectl describe node <node-name>
kubectl describe pvc <pvc-name>
Tips:
Shows events that explain failures (like CrashLoopBackOff)
Useful for debugging scheduling issues
kubectl apply
Create or update resources using declarative YAML.
kubectl apply -f deployment.yaml
Tips:
Keeps resource history intact (unlike replace)
Supports server-side apply (--server-side)
Combine with GitOps workflows
Client-Side Apply (kubectl apply)
Merge happens locally in kubectl
Reads live object from cluster, calculates a diff, sends patch
Uses last-applied-configuration annotation
Good for simple use-cases and quick workflows
Can cause conflicts if multiple actors modify the same resource
Server-Side Apply (kubectl apply --server-side)
Merge happens on the API server
Server tracks field ownership (managedFields)
Supports fine-grained conflict resolution
Better for GitOps and controllers
Requires Kubernetes v1.18+ for stability
Key Differences
Feature
Client-Side Apply
Server-Side Apply
Merge location
Local (kubectl)
API Server
Field ownership
Not tracked
Tracked (managedFields)
Conflict detection
Basic
Advanced
Annotation used
last-applied-configuration
None
Best for
Manual ops
GitOps, automation
When to Use What?
Use Client-Side for quick, manual changes
Use Server-Side for automation, GitOps, and shared control
kubectl delete
Remove a resource.
kubectl delete pod <name>
kubectl delete -f deployment.yaml
Tips:
kubectl port-forward
Expose a pod or service on your local machine.
kubectl port-forward pod/<pod-name> 8080:80
Use cases:
Debug web apps or APIs locally
Connect to internal tools (e.g., DBs, dashboards)
Understanding kubectl
kubectl get pods
kubectl describe pod <pod-name>
kubectl exec -it <pod-name> -- /bin/sh
kubectl logs <pod-name>
The foundation of working with Kubernetes
kubectl get namespaces
Switching and using namespaces effectively:
kubectl get ns
kubectl get pods -n kube-system
Always specify namespace when debugging non-default apps
Use --all-namespaces to search globally
Troubleshooting
Checking Pod Status
Use kubectl get pods to view pod states at a glance.
kubectl get pods -o wide
kubectl get pods -A
Checking Pod Status
Key STATUS values:
Running: Pod is up and ready
Pending: Waiting to be scheduled
CrashLoopBackOff: Container keeps crashing
ImagePullBackOff: Can't pull image
Terminating: Being deleted
Describing a Pod in Detail
Use kubectl describe to get details of Pod:
kubectl describe pod <pod-name>
Describing a Pod in Detail
What youโll see:
Labels & annotations
Containers, images, and resource settings
Liveness & readiness probes
Events : scheduling, image pull, startup issues
Describing a Pod in Detail
Tip:
Use grep Events or search for the bottom section for helpful logs like:
Failed to pull image...
Back-off restarting failed container
Inspecting Cluster Events
Cluster-wide events show real-time Kubernetes problems:
kubectl get events --sort-by=.metadata.creationTimestamp
Inspecting Cluster Events
Why itโs useful:
See things like:
Failed image pulls
OOMKills
Volume mounting issues
Shows exact timestamps and involved objects
Debugging Crashed Pods
If your pod is restarting or failing:
View logs from the previous container:
kubectl logs -p <pod-name>
-p (or --previous) shows logs from the last crashed attempt
Debugging Crashed Pods
Connect to a shell:
kubectl exec -it <pod-name> -- /bin/bash
/bin/bash might not be available! You may need to try /bin/sh in that case. If that's not available, try busybox. If that fails, things get more complicated...
Check env vars, files, app config
May not work if container keeps crashing before you can connect
Investigating Node Issues
See all cluster nodes:
kubectl get nodes
Inspect a specific node:
kubectl describe node <node-name>
Investigating Node Issues
What to look for:
Allocatable resources (CPU/memory)
Conditions (Ready, DiskPressure, PIDPressure)
Labels and taints
Events at the bottom (failed pods, resource pressure, etc.)
Use together:
kubectl get pods
kubectl describe pod
kubectl logs / kubectl exec
kubectl get events
kubectl describe node
This gives you a full view of:
Whatโs failing
Why it failed
Where it failed (node)
How to fix it
Troubleshooting Pod
Summary
kubectl get pods quick status
kubectl describe pod deep dive
kubectl logs -p debug restarts
kubectl exec hands-on inspection
kubectl get events context + root cause
kubectl describe node host-level issues
kubectl exec
Execute a command in a running container (like SSH).
kubectl exec -it <pod-name> -- /bin/sh
Flags & Variants:
kubectl logs
Get logs from a container in a pod.
kubectl logs <pod-name>
kubectl logs <pod-name> -c <container-name>
Helpful flags:
--previous or -p for logs from crashed container
--tail=100 to limit output
-f to follow logs (like tail -f)
Health Checks
Health Checks
Liveness Probe
Checks if unrecoverable error happened. Will restart container if it fails.
Readiness Probe
Checks if application can receive traffic.
Startup Probe
Checks if application already started.
Liveness and Readiness do not start until it succeeds.
Health Checks - HTTP Probe
Is executed in context of Pod.
livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
Health Checks - TCP Probe
Is executed in context of Node.
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
Health Checks - Command Execution Probe
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
Health Checks - Option initialDelaySeconds
Number of seconds after the container has started before startup, liveness or readiness probes are initiated. If a startup probe is defined, liveness and readiness probe delays do not begin until the startup probe has succeeded. If the value of periodSeconds is greater than initialDelaySeconds then the initialDelaySeconds would be ignored. Defaults to 0 seconds. Minimum value is 0.
Health Checks - Option periodSeconds
How often (in seconds) to perform the probe. Default to 10 seconds. The minimum value is 1.
Health Checks - Option timeoutSeconds
Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1.
Health Checks - Option successThreshold
Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup Probes. Minimum value is 1.
Health Checks - Option failureThreshold
If a probe fails failureThreshold times in a row, Kubernetes considers the container unhealthy.
For startup or liveness probes: the container is restarted.
For readiness probes: the container keeps running, but the pod is marked as not ready, and Kubernetes stops sending traffic to it.
Health Checks - Option terminationGracePeriodSeconds
You can set a grace period for how long the kubelet waits before forcefully stopping a failed container.
By default, it uses the pod's terminationGracePeriodSeconds (30s if not set), and the minimum allowed is 1 second.
You can also set this at the probe level for more control.
Understanding Kubernetes Errors
Error
Meaning
CrashLoopBackOff
App is crashing repeatedly
OOMKilled
Out of memory
ImagePullBackOff
Image can't be pulled
RunContainerError
Container failed to start
Resource Requests/Limits
What is OOMKill?
OOMKill - Common causes
Poorly set memory limits
Memory leaks or high load spikes
Requests vs. Limits
Field
What it means
Effect on scheduling
requests
Guaranteed minimum for the pod
Used by scheduler
limits
Max allowed usage (enforced by kubelet)
Enforced at runtime
CPU limits can throttle
Memory limits can OOMKill
Requests vs. Limits example
resources:
requests:
cpu: "250m"
memory: "128Mi"
limits:
cpu: "1"
memory: "512Mi"
Resource Requests vs. Scheduling
Scheduler only looks at requests , not limits
Overcommitting is allowed if requests fit
Setting and Changing Resource Limits
Option 1: YAML definition
resources:
requests:
memory: "128Mi"
limits:
memory: "256Mi"
Option 2: kubectl set resources
kubectl set resources deployment myapp \
--limits=cpu=500m,memory=512Mi \
--requests=cpu=250m,memory=256Mi
Best Practices for Resource Limits
Start with requests based on baseline usage
Set memory limits to prevent total crash
Set CPU limits only if you need to prevent resource hogging
Use monitoring tools (Prometheus, VPA) to adjust over time
Use memory requests = limits for predictable performance
Want to Simulate an OOM?
Try this pod to trigger OOMKilled:
apiVersion: v1
kind: Pod
metadata:
name: oom-demo
spec:
containers:
- name: hog
image: polinux/stress
command: ["stress" , "--vm" , "1" , "--vm-bytes" , "512M" , "--vm-hang" , "1" ]
resources:
limits:
memory: "200Mi"
Persistent Volume Claims
Persistent Volume Claims (PVCs)
What Are Persistent Volume Claims (PVCs)?
A PVC is a request for storage by a pod
It abstracts:
Storage size
Access mode (e.g., ReadWriteOnce, ReadOnlyMany)
Storage class (e.g., fast SSD vs. slow HDD)
Binds to a PersistentVolume (PV) in the cluster
Pod example with PVC
spec:
containers:
- image: nginx:latest
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
volumes:
- name: data
persistentVolumeClaim:
claimName: my-pvc
PVC with StatefulSet lifecycle
Checking PVC Status
Use kubectl to inspect PVCs:
kubectl get pvc
kubectl describe pvc <pvc-name>
Key statuses:
Bound: Successfully linked to a PV
Pending: Waiting for a suitable PV
Lost: Underlying PV missing or deleted
Checking PVC Status
Tips:
Use kubectl get pv to cross-check binding
kubectl describe shows capacity, access mode, and events
kubectl get volumeattachments -A show all attachments (useful when debugging multi-attach errors)
Editing and Resizing PVCs
kubectl edit pvc <pvc-name>
Change:
resources:
requests:
storage: 5Gi
Or patch directly:
kubectl patch pvc <pvc-name> \
-p '{"spec":{"resources":{"requests":{"storage":"5Gi"}}}}'
Deleting PVCs Safely
Always check if a pod is using the PVC :
kubectl get pod -o yaml | grep -A 5 volumeMounts
Delete with:
kubectl delete pvc <pvc-name>
Deleting PVCs Safely
PVC Deletion Impact
If reclaimPolicy is:
Delete: Volume gets removed
Retain: Volume stays in place (manual cleanup needed)
When and Why Are PVCs Needed?
Best Practices with PVCs
Choose StorageClass that fits workload (SSD vs HDD)
Set appropriate access mode (RWO, RWX, ROX)
Use PVC templates with StatefulSets:
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ReadWriteOnce ]
resources:
requests:
storage: 5Gi
Monitor PVC usage to avoid filling up volumes
Set resource quotas to prevent abuse
Thanks!
Questions?
_note: These commands form the backbone of most Kubernetes operations. Great to demo live if possible.
_note: Great starting point when checking the state of any resource. Combine with `watch` for live updates.
Show selecotr by node: --field-selector spec.nodeName=dhc-03
_note: Encouraged over imperative commands for production use.
_note: Super helpful for testing without exposing services externally.
_note: Logs, describe, and events usually reveal 80% of what you need.
_note: Use it to poke around inside a container: check logs, config, or run diagnostic commands.
_note: Mention `kubectl describe pod` and `kubectl get events` as sources of this info.
_note: Emphasize that pods don't request storage directly โ they use PVCs, which Kubernetes then matches to an appropriate PV.
_note: Useful to show the interaction between PVC, PV, and actual storage backend like Ceph, AWS EBS, etc.
_note: Resizing is often only allowed when volume is not mounted, or may require restarting the pod.