Pods Quiz
Quiz
localhost. For example, Container A can reach Container B at localhost:port.localhost. For example, Container A can reach Container B at localhost:port.containers:
- name: writer
image: busybox
command: ["/bin/sh", "-c", "echo hello > /data/message.txt"]
volumeMounts:
- name: shared-data
mountPath: /data
- name: reader
image: busybox
command: ["/bin/sh", "-c", "cat /data/message.txt"]
volumeMounts:
- name: shared-data
mountPath: /data
volumes:
- name: shared-data
emptyDir: {}Both containers mount the same volume (shared-data) at /data. The writer creates the file, and the reader can access it because they share the same emptyDir volume. This is a common pattern for data sharing between containers in a Pod.
Key concept: volumes define WHAT storage exists (Pod-level), while volumeMounts define WHERE that storage appears inside each container. The name field is the glue that connects them.
Both containers mount the same volume (shared-data) at /data. The writer creates the file, and the reader can access it because they share the same emptyDir volume. This is a common pattern for data sharing between containers in a Pod.
Key concept: volumes define WHAT storage exists (Pod-level), while volumeMounts define WHERE that storage appears inside each container. The name field is the glue that connects them.
emptyDir volumes are designed for.Sidecar Pattern
A multi-container pod pattern where auxiliary containers enhance the primary container’s functionality.
Common Use Cases:
- Log aggregation (Fluentd, Filebeat)
- Service mesh proxies (Envoy, Istio)
- Configuration reloaders
- Monitoring agents
Key Characteristic: The sidecar extends or enhances the main container without modifying its code.
Did you get it right?
spec:
initContainers:
- name: setup
image: busybox
command: ['sh', '-c', 'echo Setup complete']
- name: log-aggregator
image: fluentd
_____: _____ # Makes it a sidecar
containers:
- name: app
image: nginxinitContainers section with restartPolicy: Always. This makes them start before app containers but continue running alongside them, unlike regular init containers which terminate after completion.initContainers section with restartPolicy: Always. This makes them start before app containers but continue running alongside them, unlike regular init containers which terminate after completion.emptyDir volume is created when a Pod is assigned to a node and exists as long as the Pod runs. It’s initially empty and is commonly used for sharing data between containers in a Pod. When the Pod is removed, the data in the emptyDir is deleted.emptyDir volume is created when a Pod is assigned to a node and exists as long as the Pod runs. It’s initially empty and is commonly used for sharing data between containers in a Pod. When the Pod is removed, the data in the emptyDir is deleted.localhost. The metrics exporter would connect to localhost:80 to access nginx.localhost. The metrics exporter would connect to localhost:80 to access nginx.Adapter Pattern (translates)
A multi-container pattern where a sidecar container standardizes or normalizes the output/interface of the main container.
Example Use Case: An application produces custom metrics format → Adapter container converts to Prometheus format → Monitoring system scrapes standardized metrics
Why Use It: Allows legacy or third-party applications to integrate with standardized systems without modifying the original application.
Did you get it right?
spec:
initContainers:
- name: check-db
image: busybox
command: ['sh', '-c', 'exit 1'] # Fails
- name: setup-config
image: busybox
command: ['sh', '-c', 'echo config > /config/app.conf']
containers:
- name: app
image: myappcheck-db exits with code 1 (failure), the Pod initialization fails. The second init container (setup-config) never runs, and the application container never starts. Kubernetes will retry based on the Pod’s restart policy.check-db exits with code 1 (failure), the Pod initialization fails. The second init container (setup-config) never runs, and the application container never starts. Kubernetes will retry based on the Pod’s restart policy.db-service on port 5432 to be ready before starting the application:spec:
initContainers:
- name: wait-for-db
image: busybox:1.36
command: ['sh', '-c', '_____']
containers:
- name: app
image: myappnc -z (netcat) to check if port 5432 on db-service is accepting connections. The -z flag performs a zero-I/O scan (just checks if port is open). This is more reliable than DNS checks like nslookup because it verifies the database port is actually ready to accept connections, not just that the service name resolves.nc -z (netcat) to check if port 5432 on db-service is accepting connections. The -z flag performs a zero-I/O scan (just checks if port is open). This is more reliable than DNS checks like nslookup because it verifies the database port is actually ready to accept connections, not just that the service name resolves.initContainers section with restartPolicy: Always. This tells Kubernetes to keep the container running alongside application containers, unlike regular init containers which terminate after completion.initContainers section with restartPolicy: Always. This tells Kubernetes to keep the container running alongside application containers, unlike regular init containers which terminate after completion.Pods are Atomic Units
Pods are the smallest schedulable unit in Kubernetes. All containers in a Pod must run on the same node because:
- Shared namespaces and resources: Containers share network namespace and local volumes, requiring co-location on a single node
- Localhost communication: Containers communicate over localhost using a shared IP address (only works within same node)
- Scheduling semantics: Kubernetes schedules Pods—not individual containers—ensuring tightly coupled containers are co-located
Result: All containers in a Pod always run on the same node, enabling low-latency communication and shared resource access.
Did you get it right?