RousselTMLEARNING

Systems & Linux

Kubernetes best practices

Best practices to secure and optimize Kubernetes deployments.

Isolate with namespaces #

Use namespaces to segment and isolate resources in your clusters.

Manage configurations and secrets #

Centralize configurations and secure sensitive information with ConfigMaps and Secrets.

Use ConfigMaps #

ConfigMaps centralize application configurations, making it easier to update and manage environment variables without redeploying containers.

Store sensitive information #

Use Secrets to protect sensitive data such as passwords and API keys. Restrict access to them to keep applications secure.

Enable probes #

Ensure service availability with liveness and readiness probes.

Liveness probes #

Liveness probes automatically restart containers when they fail, improving service continuity.

Readiness probes #

Readiness probes send traffic only to containers that are ready, reducing service interruptions.

Define quotas and limits #

Limit resources for each container and namespace to avoid conflicts and optimize performance.

Automate updates #

Use rolling updates to deploy changes without service interruption.

Monitor metrics #

Performance monitoring helps diagnose problems quickly.

Monitoring tools #

Choose tools such as Prometheus or Dynatrace to collect and visualize metrics in real time, making resource management easier.

Configuring alerts #

Define alerts on critical metrics to react quickly to anomalies and avoid service interruptions.

Organize with labels and annotations #

Labels and annotations make it easier to classify and manage resources.

Limit privileges #

Apply the principle of least privilege to improve container security.

Non-root execution #

Run containers as non-root users to reduce the risk of compromise. This best practice limits privileges if a vulnerability is exploited.

Least privilege #

Apply the principle of least privilege by limiting container permissions to the resources strictly needed to run.

Enable logging #

Centralize logs to make monitoring and troubleshooting easier.

Logging tools #

Use solutions such as Fluent Bit, Grafana Alloy or the OpenTelemetry Collector (to Loki, Elasticsearch or OpenSearch) to centralize logs, improving the visibility of events in the cluster.

Schedule backups #

Regular backups ensure service continuity in the event of a disaster.

Volume backups #

Back up data volumes frequently to prevent data loss in the event of a failure.

Cluster state backup #

Regularly save the cluster state so you can easily restore configurations when needed.

Overall checklist #

The six families of practices.

Summary view #

Kubernetes best practices
Each family is detailed below with verification commands.

Reliable workloads #

Resources, probes and availability.

Reference manifest #

apiVersion: apps/v1
kind: Deployment
metadata: { name: api }
spec:
  replicas: 3
  strategy: { type: RollingUpdate, rollingUpdate: { maxSurge: 1, maxUnavailable: 0 } }
  selector: { matchLabels: { app: api } }
  template:
    metadata: { labels: { app: api } }
    spec:
      securityContext: { runAsNonRoot: true, seccompProfile: { type: RuntimeDefault } }
      topologySpreadConstraints:
        - { maxSkew: 1, topologyKey: topology.kubernetes.io/zone, whenUnsatisfiable: ScheduleAnyway, labelSelector: { matchLabels: { app: api } } }
      containers:
        - name: api
          image: registre.exemple.fr/shop/api:1.4.2@sha256:...    # version + digest
          resources: { requests: { cpu: 250m, memory: 256Mi }, limits: { memory: 512Mi } }
          readinessProbe: { httpGet: { path: /ready, port: 8080 } }
          livenessProbe:  { httpGet: { path: /healthz, port: 8080 } }
          securityContext: { allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities: { drop: [ALL] } }
kubectl get pods -A -o json | jq -r '.items[] | select(.spec.containers[].resources.requests == null) | .metadata.namespace + "/" + .metadata.name'   # pods sans requests
kubectl get pdb -A && kubectl get hpa -A
kubectl top pods -A --sort-by=memory | head

Security and governance #

Checks to automate.

Checks #

kubectl auth can-i --list --as=system:serviceaccount:prod:default
kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.roleRef.name=="cluster-admin") | .metadata.name + " -> " + ([.subjects[]?.name] | join(","))'
kubectl label ns prod pod-security.kubernetes.io/enforce=restricted --overwrite
kubectl get networkpolicy -A
kubescape scan framework nsa && trivy k8s --report summary cluster
kubectl create quota prod-quota --hard=cpu=40,memory=80Gi,pods=100 -n prod
Good practice: Enforce these rules with a policy engine (Kyverno or OPA Gatekeeper) at admission time rather than checking them after the fact.

Cluster operations #

Backups and upgrades.

Backups, upgrades, nodes #

# Sauvegarde etcd
ETCDCTL_API=3 etcdctl snapshot save /backup/etcd-$(date +%F).db --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key
# Sauvegarde applicative (Velero)
velero backup create prod-$(date +%F) --include-namespaces prod --ttl 720h
velero restore create --from-backup prod-2026-10-18
# Mise à jour contrôlée d'un nœud
kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data && kubectl uncordon worker-1
kubeadm upgrade plan

2026 update: what has changed #

Recent changes worth knowing (checked in November 2026).

Versions and lifecycle #

Kubernetes ships three minor releases a year. The 1.36 branch (April 2026) is the latest at the time of this update; each minor release gets about 14 months of fixes. Plan at least one upgrade a year and find removed APIs before upgrading.

kubectl version
kubeadm upgrade plan                 # kubeadm clusters
pluto detect-all-in-cluster          # deprecated APIs still in use (Fairwinds Pluto)

Security: today's standards #

PodSecurityPolicies are gone (Kubernetes 1.25): Pod Security Admission enforces the baseline or restricted profiles per namespace. CEL admission policies are built in: ValidatingAdmissionPolicy (stable since 1.30) and MutatingAdmissionPolicy (stable in 1.36), alongside or instead of Kyverno and Gatekeeper. User namespaces (hostUsers: false), stable in 1.36, separate the container's root user from the node's.

apiVersion: v1
kind: Namespace
metadata:
  name: prod
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/warn: restricted

Operations: what changed #

  • Logs: Fluent Bit, the OpenTelemetry Collector or Grafana Alloy replace Fluentd in most new clusters; Promtail reached end of life on March 2, 2026.
  • Native sidecars (stable since 1.33): an initContainer with restartPolicy: Always starts before the app and stops after it.
  • In-place resize of a pod's requests and limits without recreating it (stable since 1.35).
  • Ingress: the ingress-nginx project was retired in March 2026; move to another controller or to the Gateway API.

Related articles

Comparing Kubernetes offerings

A complete analysis of managed Kubernetes offerings, with strengths, features, pricing and integration.

Kubernetes scheduling strategies

An overview of scheduling strategies in Kubernetes to optimize workload management, with code examples.

Kubernetes CNI: Flannel, Calico and Cilium compared

Kubernetes CNI: understand network plugins (Container Network Interface) and compare Flannel, Calico and Cili…

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!