pdo_mysql PHP extension missing in Kubernetes Deployment

8/23/2019

I am currently deploying my Laravel application to a kubernetes cluster. I use the same docker image for the actual deployment and a migration job which is deployed via Gitlab using Helm.

The Problem: Running the migration job failes, because pdo_mysql module is not enabled (missing in php -m)

Things to know: Running same container with the same command locally docker run registry.gitlab.com/../master:TAG /bin/sh -c "php artisan:migrate" - works fine

Application container in the cluster is also working, so pdo_mysql is present.

Scheduler using supervisord to run php some:command (which needs pdo_mysql) works too.

.env file is the same for all containers

Deployment file (you can ignore the helm variables)

    {{- if .Values.application.migrateCommand -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "trackableappname" . }}-db-migrate
  labels:
    app: {{ template "appname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version| replace "+" "_" }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  annotations:
    "helm.sh/hook": pre-upgrade
    "helm.sh/hook-delete-policy": before-hook-creation
    "helm.sh/hook-weight": "0"
spec:
  template:
    metadata:
      labels:
        app: {{ template "appname" . }}
        release: {{ .Release.Name }}
    spec:
      restartPolicy: Never
      imagePullSecrets:
{{ toYaml .Values.image.secrets | indent 10 }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        command: ["/bin/sh"]
        args: ["-c", "{{ .Values.application.migrateCommand }}"]
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        {{- if .Values.application.secretName }}
        envFrom:
        - secretRef:
            name: {{ .Values.application.secretName }}
        {{- end }}
{{- end -}}

Update: helm install . --dry-run --debug

    ---
# Source: portal/templates/db-migrate-hook.yaml
apiVersion: batch/v1
    kind: Job
    metadata:
      name: cranky-seahorse-db-migrate
      labels:
        app: cranky-seahorse
        chart: "portal-0.3.0"
        release: cranky-seahorse
        heritage: Tiller
      annotations:
        "helm.sh/hook": pre-upgrade
        "helm.sh/hook-delete-policy": before-hook-creation
        "helm.sh/hook-weight": "0"
    spec:
      template:
        metadata:
          labels:
            app: cranky-seahorse
            release: cranky-seahorse
        spec:
          restartPolicy: Never
          imagePullSecrets:
              - name: gitlab-registry

          containers:
          - name: portal
            image: "gitlab.example.com/group/project:stable"
            command: ["/bin/sh"]
            args: ["-c", "sh migrate.sh"]
            imagePullPolicy: Always
---
-- mrvnklm
kubernetes
kubernetes-helm
php

1 Answer

9/3/2019

The cause of the problem can be wrong php.ini in /var/www/html that was being loaded instead of the right one (exetension_dir was being set wrongly) so please check it.

You can run:

RUN echo "extension=pdo_mysql" >> /usr/local/etc/php/php.ini \
 && service apache2 restart

This will enable extension code into the php.ini and restart apache2 so the new config gets loaded.

What I found also is github topic about it. You can also try this solution. I hope it will helps you.

-- muscat
Source: StackOverflow