简体   繁体   English

问题:最大上传文件大小:Google Kubernetes Wordpress 中的 2 MB

[英]Problem with: Maximum upload file size: 2 MB in Google Kubernetes Wordpress

I deployed this Wordpress kubernetes container: https://console.cloud.google.com/marketplace/details/google/wordpress?project我部署了这个 Wordpress kubernetes 容器: https ://console.cloud.google.com/marketplace/details/google/wordpress ? project

But I have a problem with upload the theme in Wordpress.但是我在 Wordpress 中上传主题时遇到问题。 The uploaded file exceeds the upload_max_filesize directive in php.ini.上传的文件超过了 php.ini 中的 upload_max_filesize 指令。

I can't find the file: php.ini.我找不到文件:php.ini。 in the pods of kubernetes.在 kubernetes 的 pod 中。

I tried to use plugin for edit php.ini in Wordpress https://wordpress.org/plugins/php-settings/ but it's no write the file.我尝试使用插件在 Wordpress https://wordpress.org/plugins/php-settings/ 中编辑 php.ini,但没有写入文件。

Could someone help me with a step-by-step guide to modify the container's yaml or other solution?有人可以通过分步指南帮助我修改容器的 yaml 或其他解决方案吗?

As adviced here , the recommended way is to mount a php config ini file.正如这里所建议的,推荐的方法是挂载一个 php 配置 ini 文件。 The most convenient way to expose it is using Kubernetes ConfigMaps.公开它的最方便的方法是使用 Kubernetes ConfigMaps。 Pls create a new config map:请创建一个新的配置映射:

apiVersion: v1
kind: ConfigMap
metadata:
  name: wp-php-config
  namespace: default
data:
  uploads.ini: |-
    file_uploads = On
    upload_max_filesize = 256M
    post_max_size = 256M
    memory_limit = 64M
    max_execution_time = 600

And then expose the configMap as a volume in your pod by adding the following config to you're pod spec.template.spec.containers :然后通过将以下配置添加到您的 pod spec.template.spec.containers来将 configMap 作为您的 pod 中的卷spec.template.spec.containers

... (wordpress container specs)
  volumeMounts:
    - mountPath: /usr/local/etc/php/conf.d/uploads.ini
      name: php-config
      subPath: uploads.ini

(...)

volumes:
  - configMap:
      defaultMode: 420
      name: wp-php-config
    name: php-config

You might also need to adjust your ingress max upload limit.您可能还需要调整入口最大上传限制。 Assuming you're using nginx ingress, pls decorate it with an annotation:假设您使用的是 nginx ingress,请用注释装饰它:

nginx.ingress.kubernetes.io/proxy-body-size: 50m

If you want to apply the change to the ingress globally, search for the ingress configMap and add the setting there.如果要将更改全局应用到入口,请搜索入口 configMap 并在那里添加设置。

You can execute 'kubectl get pods' to list the pods and then get into a shell using 'kubectl exec -it [POD_NAME] -- /bin/bash'.您可以执行 'kubectl get pods' 来列出 pods,然后使用 'kubectl exec -it [POD_NAME] -- /bin/bash' 进入 shell。 You can then follow methods mentiond in this link to change the value.然后,您可以按照此链接中提到的方法更改值。

Another option is to create a ConfigMap with your custom configuration similar to this link to increase the size of the upload file size.另一种选择是使用类似于此链接的自定义配置创建一个ConfigMap ,以增加上传文件的大小。

Then you need to go to your GKE workloads and in “wordpress-1-wordpress” workload of type “StatefulSet” you need to modify the YAML file where you can add the ConfigMap data to a Volume .然后,您需要转到 GKE 工作负载,在“StatefulSet”类型的“wordpress-1-wordpress”工作负载中,您需要修改 YAML 文件,您可以在其中将ConfigMap 数据添加到 Volume

Another workaround is that, you can rebuild the image that you are using in a docker file.另一种解决方法是,您可以重建您在 docker 文件中使用的映像。

This is what I did to resolve the issue:这是我为解决问题所做的工作:

  1. I added these lines to my Dockerfile我将这些行添加到我的 Dockerfile

    file upload上传文件

    RUN touch /usr/local/etc/php/conf.d/uploads.ini \\ && echo "file_uploads = On \\n\\ max_execution_time = 600 \\n\\ upload_max_filesize = 200M \\n\\ post_max_size = 200M" >> /usr/local/etc/php/conf.d/uploads.ini运行 touch /usr/local/etc/php/conf.d/uploads.ini \\ && echo "file_uploads = On \\n\\ max_execution_time = 600 \\n\\ upload_max_filesize = 200M \\n\\ post_max_size = 200M" >> /usr/local /etc/php/conf.d/uploads.ini

  2. in nginx-ingress dependencies.yml,i added these 'data' parameters in the configmap and it worked.在 nginx-ingress dependencies.yml 中,我在 configmap 中添加了这些“数据”参数并且它起作用了。

    kind: ConfigMap apiVersion: v1 metadata: name: nginx-configuration namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx data: proxy-body-size: "200m" client-max-body-size: "200m"种类:ConfigMap apiVersion:v1 元数据:名称:nginx-configuration 命名空间:ingress-nginx 标签:app.kubernetes.io/name:ingress-nginx app.kubernetes.io/part-of:ingress-nginx 数据:proxy-body-尺寸:“200m”客户端最大身体尺寸:“200m”

  3. After that, *kubectl apply -f ingress/dependencies.yml* and i was able to upload more than 2mb.之后, *kubectl apply -f ingress/dependencies.yml*并且我能够上传超过 2mb。

Try this and see if it works for you试试这个,看看它是否适合你

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

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