简体   繁体   English

Kubernetes 部署中缺少 pdo_mysql PHP 扩展

[英]pdo_mysql PHP extension missing in Kubernetes Deployment

I am currently deploying my Laravel application to a kubernetes cluster.我目前正在将我的 Laravel 应用程序部署到 kubernetes 集群。 I use the same docker image for the actual deployment and a migration job which is deployed via Gitlab using Helm.我使用相同的 docker 映像进行实际部署,并使用 Helm 通过 Gitlab 部署迁移作业。

The Problem: Running the migration job failes, because pdo_mysql module is not enabled (missing in php -m)问题:运行迁移作业失败,因为未启用 pdo_mysql 模块(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须知:在本地使用相同的命令运行相同的容器docker run registry.gitlab.com/../master:TAG /bin/sh -c "php artisan:migrate" - 工作正常

Application container in the cluster is also working, so pdo_mysql is present.集群中的应用程序容器也在工作,因此存在 pdo_mysql。

Scheduler using supervisord to run php some:command (which needs pdo_mysql) works too.使用 supervisord 运行php some:command (需要 pdo_mysql)的调度程序也可以工作。

.env file is the same for all containers .env 文件对于所有容器都是相同的

Deployment file (you can ignore the helm variables)部署文件(可以忽略 helm 变量)

    {{- 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 .更新: helm install 。 --dry-run --debug --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
---

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.问题的原因可能是正在加载的/var/www/html中的错误php.ini而不是正确的( exetension_dir设置错误),因此请检查它。

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.这将启用扩展代码到php.ini并重新启动 apache2 以便加载新配置。

What I found also is github topic about it.我发现的也是关于它的github主题。 You can also try this solution.您也可以尝试此解决方案。 I hope it will helps you.我希望它会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM