ื“ืœื’ ืœืชื•ื›ืŸ ื”ืจืืฉื™

Kube-ApiServer

๐Ÿ“Œ What Is the Kubernetes API Server?โ€‹

The Kubernetes API Server (kube-apiserver) is the central control plane component in every Kubernetes cluster.
It acts as the gateway through which all components, users, and tools interact with the cluster.

Think of it as the front door to your Kubernetes brain.


๐ŸŽฏ Core Responsibilitiesโ€‹

RoleDescription
API FrontendExposes the Kubernetes API (RESTful, HTTP/JSON)
Authentication & AuthorizationValidates user identity and access rights (RBAC, ABAC, etc.)
Admission ControlEnforces policies (e.g., resource limits, quotas, security settings)
Data ValidationChecks schema correctness of submitted YAML/JSON
Etcd InteractionPersists the cluster's state in etcd (a distributed key-value store)
Cluster State ManagementOrchestrates updates and maintains consistency across the cluster
Serving ClientsResponds to kubectl, Controllers, Operators, and other external clients

๐Ÿ” What Happens When You Run kubectl apply?โ€‹

Let's break down the process behind:

kubectl apply -f deployment.yaml

๐Ÿ“ฆ 1. kubectl parses the YAMLโ€‹

  • Validates that the file is properly formatted.
  • Reads resource kind (Deployment, Service, etc.), metadata, and spec.

๐Ÿ” 2. Authenticationโ€‹

  • kubectl contacts the API server over HTTPS.
  • Uses your kubeconfig (typically located at ~/.kube/config) to:
    • Identify the cluster endpoint
    • Provide credentials (tokens, client certs, etc.)

โœ… 3. Authorizationโ€‹

  • API Server checks what you're allowed to do (via RBAC or other mechanisms).
  • For example, are you allowed to create a Deployment in the default namespace?

๐Ÿงฐ 4. Admission Controllers Runโ€‹

If you pass authorization, Admission Controllers kick in:

  • Examples:
    • LimitRanger: Ensures resource requests/limits.
    • PodSecurityPolicy: Blocks insecure specs.
    • NamespaceLifecycle: Prevents changes in terminating namespaces.

๐Ÿ“– 5. Validation & Defaultingโ€‹

  • Checks your resource against its OpenAPI schema.
  • Adds default fields you didn't specify (e.g., restartPolicy: Always for Pods).

๐Ÿง  6. Storage in etcdโ€‹

  • The API Server persists the resource state in etcd, the cluster's source of truth.
  • etcd is a distributed key-value store optimized for fast reads/writes and versioning.

๐Ÿ” 7. Controllers Start Actingโ€‹

  • Deployment controller sees a new Deployment object in etcd.
  • It creates a ReplicaSet, which in turn creates the desired number of Pods.
  • Each controller watches for state changes and reacts to meet the "desired state".

kubectl apply stores a last-applied-configuration annotation in the object metadata to track future diffs.


๐Ÿ”’ Authentication & Authorization Layersโ€‹

๐Ÿ” Authentication Methodsโ€‹

๐Ÿ” Authentication Methodsโ€‹

  • X.509 Certificates
  • Bearer Tokens
  • OpenID Connect (OIDC)
  • Service Accounts

๐Ÿ” Authorization Modesโ€‹

  • RBAC (Role-Based Access Control) โœ… most common
  • ABAC
  • Webhook
  • Node (for kubelets)

๐Ÿ“š The Kubernetes Resource Modelโ€‹

The API Server supports hundreds of resource types, grouped by API groups and versions.

KindAPI GroupVersion
Pod"" (core group)v1
Deploymentappsv1
Ingressnetworking.k8s.iov1
CustomResourceDefinitionapiextensions.k8s.iov1

You can list all resources and their endpoints with:

kubectl api-resources

๐Ÿ“ˆ Monitoring the API Serverโ€‹

Check logs:

kubectl logs -n kube-system kube-apiserver-<node-name>

Get the node's name using:

k get node

Use Prometheus metrics (if enabled):

https://<api-server-host>:port/metrics

๐Ÿ” Security Best Practicesโ€‹

  • Use RBAC to tightly control who can do what.
  • Enable audit logs for sensitive actions.
  • Use API server flags to restrict access (e.g., --anonymous-auth=false).
  • Protect etcd (encrypt secrets at rest via EncryptionConfiguration).

๐Ÿงต Final Summaryโ€‹

RoleDescription
Entry point for all cluster actionsExposes the REST API for all Kubernetes resources
Central orchestration brainTalks to etcd, triggers controllers
Enforces access & policyAuthn, Authz, and Admission Controllers
Supports declarative workflowsPowers kubectl apply, CI/CD pipelines
Critical for cluster availabilityIf itโ€™s down, no changes can be made

The API Server is the heart of Kubernetes, and understanding how it works is crucial to operating, securing, and automating any cluster.