apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: wordpress-replicaset
  namespace: demo
  labels:
    environment: demo
    app: wordpress
spec:
  replicas: 2
  selector:
    matchLabels:
        app: wordpress
  template:
    metadata:
      labels:
          app: wordpress
    spec:
      containers:
          # https://hub.docker.com/_/mysql
          - name: mysql
            image: mysql:5
            ports:
              - containerPort: 3306
            env:  
              - name: MYSQL_ROOT_PASSWORD
                value: notreallysecret

          # https://hub.docker.com/_/wordpress/
          - name: wordpress
            image: wordpress:latest
            ports:
              - containerPort: 80
            env:
              - name: WORDPRESS_DB_HOST
                valueFrom:
                  configMapKeyRef: 
                    name: wordpress-config
                    key: db-host
              - name: WORDPRESS_DB_USER
                valueFrom:
                  configMapKeyRef: 
                    name: wordpress-config
                    key: db-user
              - name: WORDPRESS_DB_PASSWORD
                valueFrom:
                  configMapKeyRef: 
                    name: wordpress-config
                    key: db-password
            volumeMounts:
                - name: wordpress-conf
                  mountPath: /var/www/html/k8s-wp-config.php
                  subPath: wp-config.php

        # Note : the volumes declaration is at the containers declaration level, this 
        # is because all containers inside a pod share the same volumes.
      volumes:
        - name: wordpress-conf
          configMap: 
            name: wordpress-config