kubectl get nodes).kubectl configuration that defines which cluster to talk to,
which user credentials to use, and which namespace is the default. Context exists only on the
client, not in the cluster. HOW kubectl connects.In Kubernetes, there are two main ways to wire resources together:
Deployment Wiring Rule: The matchLabels in your selector must match the
labels in your template. If they don't, the Deployment will try to create a Pod, won't recognize the Pod
it just created, and will get stuck in a loop trying to create more.
template.metadata.labels: Tags every Pod generated by the manifest (e.g.,
app: webapp).selector.matchLabels: Tells the controller to look for and manage any Pods with that
label.localhost + port.A Kubernetes Service is an internal or external network abstraction that exposes a set of Pods. You need it when Pods are replicated, may restart, or when you need stable discovery and load balancing.
A Service is a distributed, cluster-wide routing rule. It causes the cluster to write routing rules (tables) on nodes. Ingress sends traffic to the Service IP, which uses kernel routing rules to reach the Pod IP. The Service IP is a virtual IP that exists conceptually in the cluster.
| Port Type | Analogy | Description |
|---|---|---|
targetPort |
Internal room number in a building | The Pod container port (e.g., nginx port) |
port |
Building's internal doorway | The K8s Service port (inside the cluster) |
nodePort |
Main gate from the street | External access port opened on every node (Range 30000–32767) |
Alternative to LoadBalancer and NodePort to expose services outside the cluster. It provides HTTP/HTTPS routing, TLS termination, and virtual hosts. Requires an Ingress Controller (e.g., NGINX, Traefik) which runs as pods inside the cluster.
Every service exposed externally gets its own cloud load balancer. Typically, you deploy one external load balancer in front of the Ingress Controller to provide a stable internet entry point. The Ingress Controller then routes traffic internally to many services.
IngressController → watches → Ingress → points to → Service → selects → Pods Deployment → manages → Pods Data Flow: Ingress → Service → Secret (for TLS) Resource Usage: Pods/Deployments/Ingress → may use → Secrets
Allows apps to find each other automatically. Kubernetes injects a custom /etc/resolv.conf into
every Pod. This points to the internal DNS service (CoreDNS) and includes search domains (e.g.,
default.svc.cluster.local), allowing you to curl by service name.
Cross-Namespace Rules:
<service>.<namespace>.svc.cluster.localExternalDNS: Automates DNS updates for external providers (AWS Route 53, Cloudflare) when services/ingresses get new IPs.
A volume defined in a Deployment (Pod spec) is available to all containers, but is mounted
only in the containers that list it in volumeMounts.
hardware=high-spec).Can be created via YAML (using Base64 encoding) or CLI:
# CLI Example for DB Passwords: echo -n "root" > ./username.txt echo -n "password" > ./password.txt kubectl create secret generic db-user-pass --from-file=./username.txt --from-file=./password.txt # CLI Example for SSL: kubectl create secret generic ssl-certificate --from-file=ssh-privatekey=~/.ssh/id_rsa --ssl-cert-=ssl-cert=mysslcert.crt
kubectl get pod -o wide: Lists Pods with additional details (Node, IP, etc.).kubectl expose deployment hello-minikube --type=NodePort --port=8080 without a
--target-port assumes the container listens on 8080. If your image listens on 80,
connections will reset.