Practice what you just read
10 free practice questions. No credit card.
Use NetworkPolicy to restrict cluster access - this is a "know it cold" task.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: prod
spec:
podSelector: {}
policyTypes:
- Ingress
- EgressapiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-frontend
namespace: prod
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
ports:
- protocol: TCP
port: 8080NetworkPolicy is only enforced by a CNI that supports it (Calico, Cilium, Weave Net). Flannel alone does not enforce policies.
Practice what you just read
10 free practice questions. No credit card.
# Control plane checks (apiserver, etcd, scheduler, controller-manager) kube-bench run --targets master # Worker node / kubelet checks kube-bench run --targets node # Inspect kubelet config that kube-bench evaluates cat /var/lib/kubelet/config.yaml
| Component | Key Setting |
|---|---|
| kube-apiserver | --anonymous-auth=false, --authorization-mode=Node,RBAC |
| etcd | Client certificate auth and peer TLS enabled |
| kubelet | anonymous auth disabled, readOnlyPort set to 0 |
Know which flags satisfy the high-severity CIS items. kube-bench maps each finding to a CIS control number and remediation.
kubectl create secret tls app-tls --cert=tls.crt --key=tls.key
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: secure-app
spec:
tls:
- hosts:
- app.example.com
secretName: app-tls
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app
port:
number: 443169.254.169.254) with egress NetworkPolicy.hostNetwork, hostPID, and hostPath unless a task truly requires them.sha512sum to the published checksum before installing.# Compare against the official SHA512 on the release page sha512sum kubernetes-server-linux-amd64.tar.gz # Block a pod from reaching the cloud metadata service # (add an egress rule that does NOT allow 169.254.169.254/32)
If a pod can reach the instance metadata service (IMDS), it may steal the node's IAM credentials. Deny it by default.