Pod security admission controller in Kubernetes - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the Pod Security Admission Controller's processing time changes as more pods are created or updated in a Kubernetes cluster.
Specifically, how does the controller's work grow when handling many pod requests?
Analyze the time complexity of the following admission controller snippet.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionWebhook
metadata:
name: pod-security-webhook
webhooks:
- name: pod-security.kubernetes.io
rules:
- operations: ["CREATE", "UPDATE"]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
admissionReviewVersions: ["v1"]
sideEffects: None
This webhook intercepts pod creation and update requests to check if they meet security standards before allowing them.
- Primary operation: The admission controller inspects each pod's security settings one by one as requests come in.
- How many times: Once per pod creation or update request.
Each pod request is checked individually, so the total work grows directly with the number of pod requests.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The work grows in a straight line as more pods are processed.
Time Complexity: O(n)
This means the time to check pods grows directly in proportion to how many pods are created or updated.
[X] Wrong: "The admission controller checks all pods in the cluster every time a new pod is created."
[OK] Correct: The controller only checks the pod in the current request, not all existing pods, so it does not do extra work for past pods.
Understanding how admission controllers scale helps you design systems that stay fast as clusters grow. This skill shows you can think about real-world system behavior clearly.
What if the admission controller also checked all existing pods in the cluster on each new pod request? How would the time complexity change?
Practice
Pod Security Admission Controller in Kubernetes?Solution
Step 1: Understand the role of Pod Security Admission Controller
This controller enforces security policies on pods to ensure they meet security standards.Step 2: Differentiate from other controllers
It does not manage networking, scheduling, or resource monitoring, which are handled by other components.Final Answer:
To enforce security policies on pods based on predefined security levels -> Option DQuick Check:
Pod Security Admission = Enforce security policies [OK]
- Confusing it with network or scheduling controllers
- Thinking it monitors resource usage
- Assuming it manages pod lifecycle
enforce mode for the Pod Security Admission Controller in a Kubernetes API server configuration?Solution
Step 1: Identify correct flag names for Pod Security Admission
The correct flags are--enable-admission-plugins=PodSecurityand--pod-security-enforce=LEVELwhere LEVEL is one of privileged, baseline, or restricted.Step 2: Verify option syntax and values
--enable-admission-plugins=PodSecurity --pod-security-enforce=restricted: --enable-admission-plugins=PodSecurity --pod-security-enforce=restricted uses correct flag names and a valid security level 'restricted'. Options A uses invalid level, B uses incorrect flag --pod-security-mode, and C uses deprecated --admission-control.Final Answer:
--enable-admission-plugins=PodSecurity --pod-security-enforce=restricted -> Option CQuick Check:
Correct flags + valid level = --enable-admission-plugins=PodSecurity --pod-security-enforce=restricted [OK]
- Using wrong flag names like --admission-control
- Confusing enforce mode with audit or warn
- Using invalid security levels
apiVersion: policy/v1
kind: PodSecurity
metadata:
name: enforce-baseline
spec:
enforce:
level: baseline
version: "latest"
warn:
level: restricted
version: "latest"
audit:
level: privileged
version: "latest"What will happen if a pod with privileged permissions is created?
Solution
Step 1: Understand enforcement level
Theenforcelevel is set tobaseline, which blocks pods that do not meet baseline security standards, including privileged pods.Step 2: Analyze pod permissions against levels
Privileged pods exceed baseline restrictions, so enforcement blocks creation. Warnings and audits apply to lower levels but enforcement is strictest.Final Answer:
The pod creation will be blocked due to enforcement at baseline level -> Option AQuick Check:
Enforce baseline blocks privileged pods [OK]
- Confusing warn or audit with enforce
- Assuming privileged pods pass baseline enforcement
- Ignoring enforcement priority over warnings
--pod-security-enforce=restricted, but pods with privileged containers are still being created. What is the most likely cause?Solution
Step 1: Check admission controller enablement
If the controller was not enabled, no enforcement would occur cluster-wide, but the question implies partial enforcement.Step 2: Understand namespace labels impact
Namespaces can be labeled to exempt or relax enforcement, allowing privileged pods despite cluster-wide settings.Step 3: Consider other options
Incorrect pod specs or Kubernetes version issues would cause errors or no enforcement at all, not selective allowance.Final Answer:
The pods are created in namespaces labeled to exempt enforcement -> Option AQuick Check:
Namespace labels can exempt enforcement [OK]
- Assuming controller is disabled without checking labels
- Ignoring namespace-level exemptions
- Blaming pod spec errors for enforcement bypass
trusted. How should you configure this?Solution
Step 1: Understand security levels and hostPath restrictions
Therestrictedlevel blocks hostPath volumes, whileprivilegedallows them.Step 2: Apply cluster-wide enforcement and namespace override
Set cluster-wide enforcement torestrictedto block hostPath everywhere by default. Label thetrustednamespace withpod-security.kubernetes.io/enforce: privilegedto allow exceptions.Step 3: Verify option correctness
Set cluster-wide enforcement torestrictedand label thetrustednamespace withpod-security.kubernetes.io/enforce: privilegedcorrectly sets cluster-wide to restricted and trusted namespace to privileged, allowing hostPath only there.Final Answer:
Set cluster-wide enforcement to restricted and label the trusted namespace with pod-security.kubernetes.io/enforce: privileged -> Option BQuick Check:
Cluster restricted + trusted privileged = hostPath allowed only in trusted [OK]
- Setting cluster enforcement too low to block hostPath
- Using baseline instead of privileged for exceptions
- Labeling trusted namespace with a stricter level
