HPA for PHP FPM and Nginx or Pod with both Containers?

Learning about Horizontal Pod Autoscalers. Still rather confused on how to set one up for my PHP App.

Current Setup

Currently have a setup with these deployments/pods behind an ingress nginx resource:

  • php fpm
  • php worker
  • nginx
  • mysql
  • redis
  • workspace

NB The database services may be replaced by managed database services so that would leave me with 4 pods.

Horizontal Pod Autoscaler Setup

Now to run an HPA I could add this as a resource part of the php deployment (based on DO article)

. . .
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: php
    spec:
      containers:
      - image: myphpimage
        imagePullPolicy: Always
        name: nginx
        resources:
          limits:
            cpu: 300m
          requests:
            cpu: 100m
            memory: 250Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
. . .

to the php fpm app pod and have it replicate when need be and trigger Cluster Autoscaling in return. But All Ingress data will hit Nginx pod first, not PHP FPM.

Ingress Nginx Setup

From Ingress all goes to the Nginx Service which accesses the Nginx web server:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-resource
  namespace: smt-local
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    # host can be set in /etc/host or with laravel valet `valet link`
  - host: smart48k8.local
    http:
      paths:
        # https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types 
        # `/` is all paths using Prefix
      - pathType: Prefix
        path: /
        backend:
          service:
            # refers to our app service exposed to the cluster
            name: nginx-service
            port:
              number: 80

So it feels like I need to take care of Nginx scaling as well at least…

Options

Now, to have HPA deal with Nginx and PHP FPM I could either:

  1. Add two HPA - one for php and one for nginx
  2. merge the Nginx and PHP FPM deployments as two containers in one pod and HPA them

Questions

  1. I could do choice one and scale both pods, but I wonder how that could work… Perhaps I get 5 Nginx pods and 10 php pods… would ingress nginx and all still play nice?
  2. I could go for the second option, but then I wonder, wil my nginx service still work well? Is this possible?
  3. PHP App Examples - Are there HPA PHP App example setups with horizontal pod autoscaling you can recommend?