简体   繁体   中英

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

But I have a problem with upload the theme in Wordpress. The uploaded file exceeds the upload_max_filesize directive in php.ini.

I can't find the file: php.ini. in the pods of kubernetes.

I tried to use plugin for edit php.ini in Wordpress https://wordpress.org/plugins/php-settings/ but it's no write the file.

Could someone help me with a step-by-step guide to modify the container's yaml or other solution?

As adviced here , the recommended way is to mount a php config ini file. The most convenient way to expose it is using 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 :

... (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.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.

You can execute 'kubectl get pods' to list the pods and then get into a shell using 'kubectl exec -it [POD_NAME] -- /bin/bash'. 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.

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 .

Another workaround is that, you can rebuild the image that you are using in a docker file.

This is what I did to resolve the issue:

  1. I added these lines to my 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

  2. in nginx-ingress dependencies.yml,i added these 'data' parameters in the configmap and it worked.

    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"

  3. After that, *kubectl apply -f ingress/dependencies.yml* and i was able to upload more than 2mb.

Try this and see if it works for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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