KubernetesLXX · API ServerAPI server
API server flags and configuration — secure-port, audit, encryption
What you'll learn
- Identify the flags every API server operator must know
- Configure audit logging and encryption at rest
- Reason about how flag changes propagate
- Apply flag changes safely in production
Prerequisites
Verified against Kubernetes 1.34.x · kubeadm 1.34.x · kubectl 1.34.x · etcd 3.6.x · CoreDNS 1.11.x · containerd 1.7.x / 2.x · 2026-08-16
The kube-apiserver has dozens of flags; production operators only need to know a small subset: those that control security (TLS, audit, encryption), runtime behaviour (rate limits, profiling), and integration (API aggregator, etcd connection). This lesson walks the flags that matter most, where they live in kubeadm, and the discipline of changing them.
Where the flags live
For a kubeadm-managed cluster:
sudo cat /etc/kubernetes/manifests/kube-apiserver.yaml
The static pod manifest contains the flags as command-line arguments:
spec:
containers:
- name: kube-apiserver
image: registry.k8s.io/kube-apiserver:v1.34.x
command:
- kube-apiserver
- --advertise-address=10.0.1.10
- --allow-privileged=true
- --authorization-mode=Node,RBAC
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --enable-admission-plugins=NodeRestriction
- --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
- --etcd-servers=https://127.0.0.1:2379
- --service-cluster-ip-range=10.96.0.0/16
- --service-account-key-file=/etc/kubernetes/pki/sa.key
- --service-account-signing-key-file=/etc/kubernetes/pki/sa.key
- --service-account-issuer=https://kubernetes.default.svc.cluster.local
- --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
- --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
The flags every operator must understand
Authentication and authorisation
| Flag | Default | Purpose |
|---|---|---|
--client-ca-file | none | CA bundle for verifying client certs |
--api-token-csv | none | Legacy static tokens (rarely used in production) |
--oidc-* | disabled | OIDC integration config |
--authorization-mode | AlwaysAllow | Modes: Node, RBAC, Webhook, ABAC |
--enable-bootstrap-token-auth | false | Bootstrap tokens for kubeadm join |
Network and TLS
| Flag | Default | Purpose |
|---|---|---|
--secure-port | 6443 | The HTTPS port |
--bind-address | 0.0.0.0 | Bind address for the secure port |
--advertise-address | first non-loopback IP | Address to advertise to clients |
--tls-cert-file | none | Server cert for the secure port |
--tls-private-key-file | none | Server key |
etcd
| Flag | Default | Purpose |
|---|---|---|
--etcd-servers | none | Comma-separated list of etcd URLs |
--etcd-cafile | none | CA for etcd server cert verification |
--etcd-certfile | none | Client cert |
--etcd-keyfile | none | Client key |
The etcd URL list is typically three entries
(https://10.0.1.10:2379,https://10.0.1.11:2379,...).
Service accounts
| Flag | Default | Purpose |
|---|---|---|
--service-account-issuer | none | OIDC issuer URL for SA tokens |
--service-account-key-file | none | Public key file for token verification |
--service-account-signing-key-file | none | Private key for signing tokens |
The --service-account-issuer and signing key are
central to Kubernetes’ projected ServiceAccount tokens
(PART LX — Service Accounts).
Audit logging
--audit-policy-file=/etc/kubernetes/audit-policy.yaml
--audit-log-path=/var/log/kubernetes/audit/audit.log
--audit-log-maxage=30
--audit-log-maxbackup=10
--audit-log-maxsize=100
The audit policy file is a YAML configuration:
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata
namespaces: ["kube-system"]
resources:
- group: ""
resources: ["secrets", "configmaps"]
- level: RequestResponse
verbs: ["create", "delete", "update"]
The policy’s rules determine what gets logged.
Encryption at rest
--encryption-provider-config=/etc/kubernetes/encryption-config.yaml
The configuration file (Part XXI) controls Secret encryption. The API server encrypts configured resources on write; decryption happens on read.
Rate limiting and profiling
| Flag | Default | Purpose |
|---|---|---|
--max-requests-inflight | 400 | Max concurrent requests |
--max-mutating-requests-inflight | 200 | Max concurrent mutating requests |
--enable-profiling | false | pprof profiling endpoint |
--profiling-bind-address | localhost | Address for profiling |
--enable-profiling=true exposes /debug/pprof for
performance investigation; production typically enables
this on a control-plane host with restricted access.
$ crictl exec <api-server-pod-id> /server --print-flags | grep -E '(secure-port|etcd-servers|audit)' | head...Editing the manifest safely
To add a flag to the API server:
- Capture the current manifest:
sudo cp /etc/kubernetes/manifests/kube-apiserver.yaml \
/backup/kube-apiserver.yaml.$(date +%Y%m%d-%H%M)
- Edit the manifest:
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
# Add the new flag, e.g., `--enable-profiling=true`
- The kubelet observes the change and restarts the pod:
sleep 10
crictl pods | grep apiserver
# Observe: old pod stopped, new pod starting
- Verify the flag took effect:
# The id of the new pod, from the `crictl pods` output above:
API_SERVER_POD_ID=8f3c1a9d4e7b2
crictl exec "$API_SERVER_POD_ID" /server --print-flags | grep profiling
# Or kubectl logs on the API server pod
Common flag operations
Enable profiling
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
# Add:
# - --enable-profiling=true
# - --profiling-bind-address=127.0.0.1
# (or expose via port forward to localhost)
Configure audit logging
sudo vi /etc/kubernetes/audit-policy.yaml
# ... write the policy
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
# Add:
# - --audit-policy-file=/etc/kubernetes/audit-policy.yaml
# - --audit-log-path=/var/log/kubernetes/audit/audit.log
# - --audit-log-maxage=30
# - --audit-log-maxbackup=10
# - --audit-log-maxsize=100
The audit log directory must exist and be writable by the API server process.
Configure encryption at rest
sudo vi /etc/kubernetes/encryption-config.yaml
# ... write the EncryptionConfiguration
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
# Add:
# - --encryption-provider-config=/etc/kubernetes/encryption-config.yaml
After the restart, re-write all Secrets:
kubectl get secrets -A -o json | kubectl replace -f -
The flag validation
Some flags have specific format requirements:
--tls-cert-filemust point to a PEM file.--etcd-serversmust be HTTPS URLs.--service-account-issuermust be a URL.--authorization-modemust be a comma-separated list of valid modes.
A misconfigured flag prevents the API server from starting; the kubelet logs the failure.
$ crictl logs <api-server-pod-id> | tail -30Error: invalid value "AlwaysDeny" for flag -authorization-mode ... "Mode ["AlwaysDeny"] not in [Node,RBAC,...]"API server metrics
The API server exposes metrics for SLO monitoring:
# API server requests by verb and resource
apiserver_request_total{verb="create",resource="pods",code="200"}
# Latency by step
apiserver_admission_step_advertised_duration_seconds{operation="mutating_webhook"}
# Watch totals
apiserver_watch_total{resource="pods"}
The metrics surface is the production discipline: every production API server should have these metrics flowing to Prometheus.
The reload-capable flags
Some flags support hot reload without restart:
--audit-policy-file: file watches; the API server reloads on changes.
Most other flags require a pod restart.
Quiz
Knowledge check · 4 questions
Q1. Which flag controls the API server's HTTPS listening port?
Q2. Enabling encryption at rest on the API server requires editing the static-pod manifest and pointing to a new EncryptionConfiguration.
Q3. Audit logging is enabled but never logging. Diagnose.
API server has --audit-policy-file and --audit-log-path configured. The kubelet has restarted the API server. The audit log file exists but is empty.
Q4. What does --service-account-issuer do and why does it matter?
Passing score: 75%. Answers are checked in this browser.
Production discipline
- Touch the manifest rarely. Each flag change is a restart; changes accumulate risk.
- Capture before editing. cp the manifest aside; the
rollback is a
mvback. - Verify after restart. The new flag should appear in
crictl logsorkubectl logson the new pod. - Audit logging is mandatory. The audit log is the compliance evidence; without it, the cluster fails PCI / HIPAA / SOC 2 audits.
- Encryption at rest is mandatory for production credentials. AES-GCM at minimum; KMS for high-value secrets.
API server flags are the levers for cluster security and behaviour. Change one at a time; verify each.