Running WordPress in Kubernetes – Spreading Pods across Nodes

In a previous post, I went over details on the WHY we need to spread pods across nodes and how to achieve this. If you haven’t gotten a chance, please do read that article. In this post, I am going to apply the guidance presented there to spread WordPress Deployment pods across nodes.

Deployment Spec

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  replicas: 3
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - wordpress
              topologyKey: kubernetes.io/hostname
            weight: 100
      containers:
      - name: wordpress
        image: wordpress:5.5.1-php7.4-apache
        # rest of declaration

Leave a Reply

Your email address will not be published. Required fields are marked *