Loading blog posts...
Loading blog posts...
Laden...
Kubernetes draaien in productie vraagt om zorgvuldige planning en het naleven van best practices. Deze gids behandelt essentiƫle strategieƫn voor het deployen en beheren van productie-waardige Kubernetes clusters.
yamlresources: requests: memory: "256Mi" cpu: "500m" limits: memory: "512Mi" cpu: "1000m"
Voordelen:
Automatisch schalen op basis van metrics:
yamlapiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: my-app spec: minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70
Draai nooit enkele instances in productie:
yamlspec: replicas: 3
Bescherm tegen verstoringen:
yamlapiVersion: policy/v1 kind:PodDisruptionBudget metadata: name: my-app-pdb spec: minAvailable: 2 selector: matchLabels: app: my-app
Verdeel pods over nodes:
yamlaffinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 podAffinityTerm: labelSelector: matchExpressions: - key: app operator: In values: - my-app topologyKey: kubernetes.io/hostname
Beheer verkeer tussen pods:
yamlapiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: api-allow spec: podSelector: matchLabels: app: api policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app: frontend
Implementeer least privilege access:
yamlapiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: pod-reader rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "list"]
Draai containers met minimale privileges:
yamlsecurityContext: runAsNonRoot: true runAsUser: 1000 allowPrivilegeEscalation: false readOnlyRootFilesystem: true
Handhaaf beveiligingsbeleid:
yamlapiVersion: v1 kind: Namespace metadata: name: production labels: pod-security.kubernetes.io/enforce: restricted
Hardcode nooit configuratie:
yaml# ConfigMap apiVersion: v1 kind: ConfigMap metadata: name: app-config data: app.properties: | log_level=info timeout=30 # Secret apiVersion: v1 kind: Secret metadata: name: app-secrets type: Opaque data: api-key: <base64-encoded-value>
Overweeg tools zoals:
Herstart ongezonde containers:
yamllivenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 30 periodSeconds: 10
Beheer verkeer naar pods:
yamlreadinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 5 periodSeconds: 5
Handel langzaam startende applicaties af:
yamlstartupProbe: httpGet: path: /startup port: 8080 failureThreshold: 30 periodSeconds: 10
Deploy Prometheus stack:
Gebruik ELK of EFK stack:
Implementeer met:
Standaard strategie met configuratie:
yamlstrategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1
Gebruik services om verkeer te schakelen:
yaml# Blue (huidige) selector: app: my-app version: v1 # Schakel naar Green selector: app: my-app version: v2
Geleidelijke uitrol met traffic splitting
Regelmatige backups van:
Monitor en pas aan:
Pas cluster grootte automatisch aan:
yamlapiVersion: autoscaling/v1 kind: ClusterAutoscaler spec: minNodes: 3 maxNodes: 10
Gebruik voor niet-kritieke workloads:
production
staging
development
team-api
team-frontend
team-data
Beperk resources per namespace:
yamlapiVersion: v1 kind: ResourceQuota metadata: name: compute-quota spec: hard: requests.cpu: "10" requests.memory: 20Gi limits.cpu: "20" limits.memory: 40Gi
Plan voor:
Kubernetes draaien in productie vereist aandacht voor detail en naleving van best practices. Focus op:
Begin met deze fundamenten, itereer op basis van je behoeften, en verbeter continu je Kubernetes operaties. De investering in goede setup en beheer betaalt zich terug in stabiliteit, beveiliging en operationele efficiƫntie.