Kubernetes Essentials
Deploy, configure, secure, scale, and troubleshoot container workloads with Kubernetes.
Setup
Install kubectl and connect it to an existing Kubernetes cluster.
Install kubectl on Linux, macOS, or Windows and verify the client.
# macOS
brew install kubectl
# Windows
winget install -e --id Kubernetes.kubectlInstall minikube and start a local learning cluster.
# macOS
brew install minikube
# Windows
winget install Kubernetes.minikubeSelect a kubeconfig context and verify connectivity.
kubectl config get-contexts
kubectl cluster-infoArchitecture and Objects
Understand cluster components and Kubernetes API objects.
Identify the control plane and worker-node responsibilities.
kubectl cluster-info
kubectl get nodesDeclare desired state with apiVersion, kind, metadata, and spec.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: web
image: nginx:1.29kubectl and Contexts
Connect to clusters and inspect resources safely.
Select the cluster, user, and default namespace.
kubectl config current-context
kubectl config get-contextsGet resources in useful output formats.
kubectl get pods
kubectl describe pod webDeclarative Management
Preview and apply version-controlled manifests.
Manage desired state from files.
kubectl diff -f app.yaml
kubectl apply -f app.yamlLabels and Metadata
Organize and select related resources.
Attach queryable labels and descriptive annotations.
kubectl label pod web env=prod
kubectl get pods -l env=prodPods
Run one or more tightly coupled containers.
Inspect, enter, and forward ports to Pods.
kubectl get pods
kubectl logs webDeployments and Rollouts
Run and update interchangeable application replicas.
Manage stateless replicated workloads.
kubectl create deployment web --image=nginx:1.29
kubectl scale deployment web --replicas=3Inspect, pause, resume, restart, or undo updates.
kubectl rollout status deployment/web
kubectl rollout history deployment/webOther Workloads
Choose controllers for stateful, node-level, and finite work.
Run stable identities or one Pod per selected node.
kubectl get statefulsets
kubectl get daemonsetsRun tasks to completion once or on a schedule.
kubectl create job report --image=busybox:1.37 -- echo readyServices and Networking
Expose stable endpoints and route application traffic.
Provide stable discovery for selected Pods.
kubectl expose deployment web --port=80 --target-port=8080Route external HTTP traffic through an Ingress controller.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80Configuration
Inject non-secret and sensitive configuration.
Create configuration and expose it to Pods.
kubectl create configmap app-config --from-literal=LOG_LEVEL=info
kubectl create secret generic db --from-literal=password='change-me'Health and Resources
Declare health checks and resource expectations.
Separate startup, readiness, and liveness checks.
readinessProbe:
httpGet:
path: /ready
port: 8080Reserve scheduler capacity and cap container use.
resources:
requests: {cpu: 100m, memory: 128Mi}
limits: {cpu: 500m, memory: 256Mi}Storage
Attach ephemeral and persistent data to workloads.
Request persistent storage through a StorageClass.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 10GiScheduling
Influence where Pods run.
Constrain or repel Pods during scheduling.
nodeSelector:
disktype: ssdSecurity
Limit workload identity and container privileges.
Grant the minimum API permissions required.
kubectl create serviceaccount reporter
kubectl auth can-i list pods --as=system:serviceaccount:default:reporterRun containers with reduced privileges.
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: falseTroubleshooting
Find failures using status, events, logs, and ephemeral debugging.
Follow a repeatable inspection sequence.
kubectl get pods
kubectl describe pod web
kubectl logs web