Im trying to put a php symfony project on kubernetes !
It work but my php-fpm is slow to start
I build this as one pod with one php container and one nginx container
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-deployment
namespace: {{ .Values.namespace }}
labels:
app: php
spec:
replicas: {{ .Values.php.replicas }}
selector:
matchLabels:
app: php
minReadySeconds: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25% # Specifies the maximum number of Pods that can be unavailable during the update process (in percentage or number).
maxSurge: 25% # Specifies the maximum number of additional Pods that can be created above the desired number of Pods during the update process (in percentage or number).
template:
metadata:
labels:
app: php
spec:
terminationGracePeriodSeconds: 15
initContainers:
- name: init-symfony
image: {{ .Values.php.image }}
command: ["/bin/sh", "-c"]
args:
- |
cp -R /var/www/symfony/. /var/www/share
cd /var/www/share
php bin/console c:c || true
chown www-data:www-data -R .
env:
- name: DATABASE_URL
value: 'postgresql://dummy:dummy@dummy:5432/dummy?serverVersion=14'
volumeMounts:
- name: www-storage
mountPath: /var/www/share
containers:
- name: php
image: {{ .Values.php.image }}
command: ["/bin/sh", "-c"]
args:
- |
php-fpm
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 15"]
# resources:
# requests:
# memory: "1024Mi"
# cpu: "50m"
# limits:
# memory: "2048Mi"
# cpu: "100m"
readinessProbe:
tcpSocket:
port: 9000
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
ports:
- containerPort: 9000
volumeMounts:
- name: php-config-volume
mountPath: /var/www/symfony/.env.local
subPath: php.conf
- name: www-storage
mountPath: /var/www/symfony
- name: key-storage
mountPath: /var/www/symfony/config/jwt
- name: nginx
image: {{ .Values.php.image }}
resources:
requests:
memory: "64Mi"
cpu: "10m"
readinessProbe:
httpGet:
path: /nginx/heal
port: 80
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
ports:
- containerPort: 80
volumeMounts:
- name: www-storage
mountPath: /var/www/symfony
volumes:
- name: php-config-volume
configMap:
name: php-config
- name: www-storage
emptyDir: {}
- name: key-storage
persistentVolumeClaim:
claimName: pv-key-claim
So with this chart when i restart or do a rolling update my first container wait the second to be ready (so php-fpm is running on port 9000 and nginx on 80)
On my nginx i created a /nginx/health to check when it is ready
I tried to run my pod without runing php-fpm and start it by hand with the command php-fpm (it write php-fpm is ready to handle connection) and it take a lot of time ‘arround 30 seconds’ to show my page
One of the solution that i get is to put the nginx readyness probe to smt high that fpm can start without terminating the old pod
but i wonder why php-fpm tell me that he is listening for request but is not fully ready
Thanks 😀 !
2
Answers
I found a solution ! With my first Deployement. In the php container cmd i added before the php-fpm, a cache clear and a cache warmup and it fixed all my problems
PHP-FPM’s delayed readiness can be due to several factors, including the readiness probe configuration, resource allocation, or caching/warming up issues in Symfony.
Try increasing the initialDelaySeconds and periodSeconds values. Setting initialDelaySeconds to around 20–30 seconds could give PHP-FPM time to initialize fully before Kubernetes checks readiness.
Assuming your Dockerfile for PHP-FPM and NGINX for Symfony is ready and pushed
Configure your yamls accordingly
pvc
deployment
service
checkout symfony dockerfile and build symfony on k8s