How does Kubernetes decide which node to schedule a pod on?
Show the answer
The Kubernetes scheduler follows a two-phase process:
Filtering (Predicates): eliminates nodes that can't run the pod — checks resource requests (CPU/memory), node selectors, taints/tolerations, affinity/anti-affinity rules, volume topology constraints, and port availability.
Scoring (Priorities): ranks the remaining nodes using weighted scoring functions — least-requested resources, balanced resource allocation, inter-pod affinity, image locality (prefer nodes that already have the image).
The node with the highest score wins. If scores are tied, one is chosen at random. Custom schedulers or scheduler extenders can augment this logic.
What happens internally when you run kubectl apply?
Show the answer
kubectl serializes the resource manifest to JSON and sends a PATCH (strategic merge patch) or PUT request to the Kubernetes API server.
The API server authenticates (mTLS/token) and authorizes (RBAC) the request.
Admission controllers run (Mutating webhooks first, then Validating webhooks).
The object is persisted to etcd.
The relevant controller (e.g., Deployment controller) watches etcd for changes via the informer/watch mechanism.
The controller reconciles the desired state: creates/updates ReplicaSets, which create Pods.
The scheduler assigns unscheduled pods to nodes.
The kubelet on the assigned node pulls the image and starts the container via containerd/runc.
How does Kubernetes service discovery work?
Show the answer
Kubernetes uses CoreDNS (cluster DNS) for service discovery:
Every Service gets a DNS A record: ..svc.cluster.local.
Pods resolve this name via the cluster DNS server (configured in /etc/resolv.conf of each pod).
For ClusterIP services, the kube-proxy (or eBPF/Cilium) programs iptables/ipvs rules to DNAT traffic to the Service's ClusterIP → load-balance to one of the backing pod IPs (Endpoints).
Headless services (clusterIP: None) return the pod IPs directly in DNS, enabling stateful peer discovery (e.g., for StatefulSets).
82 more in the member app, with practice sets and your own marks. Join free