Advanced Kubernetes Topics and Architecture
Explain the concept of a Kubernetes Operator and provide an example of when you would use one.
Answer:
A Kubernetes Operator is a method of packaging, deploying, and managing a Kubernetes-native application. It extends Kubernetes API to create, configure, and manage instances of complex applications. You would use an Operator for stateful applications like databases (e.g., Cassandra, MySQL) to automate tasks like backups, upgrades, and scaling.
Describe the purpose of a Custom Resource Definition (CRD) in Kubernetes.
Answer:
A Custom Resource Definition (CRD) allows you to define your own custom resources in Kubernetes, extending the Kubernetes API. This enables you to store and retrieve structured data that Kubernetes can manage. CRDs are fundamental for building Operators and defining application-specific objects.
How does the Kubernetes API Server handle authentication and authorization for requests?
Answer:
The API Server handles authentication through various methods like client certificates, bearer tokens, or service account tokens. After authentication, authorization is performed using modules like RBAC (Role-Based Access Control), Node authorization, or ABAC (Attribute-Based Access Control). RBAC is the most common, defining roles with permissions and binding them to users or service accounts.
What is the difference between a DaemonSet and a Deployment in Kubernetes?
Answer:
A Deployment manages a set of identical pods, ensuring a desired number of replicas are running across the cluster, typically for stateless applications. A DaemonSet ensures that all (or some) nodes run a copy of a pod, useful for cluster-level services like log collectors (e.g., Fluentd) or monitoring agents (e.g., Node Exporter) that need to run on every node.
Explain the concept of Pod Security Policies (PSPs) and why they are being deprecated.
Answer:
Pod Security Policies (PSPs) were an admission controller that enforced security standards on pods and containers. They allowed cluster administrators to control security-sensitive aspects like privileged mode, host network access, and volume types. PSPs are being deprecated in favor of Pod Security Admission (PSA) and policy engines like OPA Gatekeeper, which offer more flexible and granular control.
How do you achieve high availability for the Kubernetes control plane?
Answer:
High availability for the control plane is achieved by running multiple instances of the API Server, etcd, Controller Manager, and Scheduler. etcd typically runs as a quorum-based cluster (e.g., 3 or 5 nodes). A load balancer is placed in front of the API Servers to distribute traffic and provide failover.
What is a mutating admission webhook and how can it be used?
Answer:
A mutating admission webhook is an HTTP callback that can modify requests to the Kubernetes API server before they are persisted. It can inject sidecar containers, add labels/annotations, or set default values for fields. For example, it can automatically inject a istio-proxy sidecar into pods for service mesh integration.
Describe the role of etcd in a Kubernetes cluster.
Answer:
etcd serves as Kubernetes' consistent and highly available key-value store. It stores all cluster data, including configuration, state, and metadata for all Kubernetes objects (pods, deployments, services, etc.). It's critical for the cluster's operation, and its availability directly impacts the cluster's health.
How does Kubernetes handle network policy enforcement?
Answer:
Kubernetes Network Policies are specifications that define how groups of pods are allowed to communicate with each other and with external endpoints. They are implemented by a network plugin (CNI) that supports NetworkPolicy, such as Calico, Cilium, or Weave Net. The CNI plugin translates these policies into firewall rules.
What are Taints and Tolerations, and how are they used for pod scheduling?
Answer:
Taints are applied to nodes, marking them as 'unsuitable' for certain pods unless those pods have matching Tolerations. Tolerations are applied to pods, allowing them to be scheduled on tainted nodes. This mechanism is used to reserve nodes for specific workloads (e.g., GPU nodes) or to evict pods from unhealthy nodes.