Skip to content Skip to sidebar Skip to footer

Increase File Upload Size Ingress Ngnix Annotation

Previously I had installed wordpress pods on Kubernetes and information technology fabricated information technology very like shooting fish in a barrel to administer and add multiple sites for clients. However, as time went on they started getting more ambitious in the different themes they were uploading. To solve the trouble required configuration changes in 2 places.

  • The Ingress Controller
  • The PHP file on the WordPress pod itself.

Ingress Controller

The first inkling that the ingress controller was having bug was that the wordpress pods I'1000 running are using Apache. So I knew information technology was something in the Nginx Ingress controller because the mistake stated:

413 Request Entity Also Large

Fixing this was a matter of changing the nginx configmap for the ingress controller. To do this information technology's a elementary matter of typing the following:

          kubectl edit cm -n ingress-nginx nginx-configuration        

In one case in here, I noticed that there was no customization so I had to create a data section. I used the following values, which probably increased it a fiddling likewise much and and then I brought them lower. Here is the case:

          apiVersion: v1 data:   customer-body-buffer-size: 32M   proxy-torso-size: 1G   proxy-buffering: "off"   proxy-read-timeout: "600"   proxy-send-timeout: "600" kind: ConfigMap metadata:   labels:     app.kubernetes.io/name: ingress-nginx     app.kubernetes.io/role-of: ingress-nginx   name: nginx-configuration   namespace: ingress-nginx        

Increasing the read and write timeouts allows larger files more than time to upload. Increasing the body size is what actually allows big files. Yous probably desire something less than 1Gb. The client-torso-buffer-size allows united states of america to utilize more retentiveness instead of writing temp files while the file is uploaded.

With this in place the client was able to effort uploading once more, but now was confronted with a problem on the actual wordpress pod.

Updating PHP params on wordpress

By examining the logs in wordpress we saw:

PHP Alarm:  Mail Content-Length of 14982910 bytes exceeds the limit of 8388608 bytes

Here we are running into a PHP limit. Through trial and error I saw I needed to increase two dissimilar parameters:

  • upload_max_filesize – the max size the upload could be
  • post_max_size – the max size the body could be.

If we weren't using Kubernetes, it would be simple to go into each server, change the param in the php.ini file and then restart, but that's not how we work in the container world. Nosotros need it to exist reproducible. Similarly for using ConfigMaps in the Nginx Ingress controller, we can utilise ConfigMaps in our WordPress application every bit well.

Create custom-ini ConfigMap

Nosotros are using the container for our wordpress instances called wordpress:v.2-apache. We can see where the config files are past logging into the server:

kubectl exec -it -due north wordpress wordpress-6bc44c5c69-zjr6z -- /bin/bash

Afterwards we can run the env | grep PHP we meet that PHP_INI_DIR is set to /usr/local/etc/php. Then all we need to do is create a custom.ini file and put it into the ./conf.d directory in that path and our changes will be activated. Our configMap code is below:

          apiVersion: v1 kind: ConfigMap metadata:   name: custom-ini   namespace: wordpress data:   custom.ini: |     upload_max_filesize = 60M     post_max_size = 60M        

We are using the wordpress namespace and calling this configMap custom-ini.

Updating the Deployment

In our deployment file we will add this configMap as a mountain selection. Nosotros are using secrets files for keeping the passwords to connect to the MySQL pod too, so there are more than ane configMaps in here, but that is a post for another time. The important parts are the post-obit:

                      volumeMounts:         - proper noun: wordpress-persistent-storage           mountPath: /var/www/html         - proper noun: config-volume           mountPath: /usr/local/etc/php/conf.d/custom.ini           subPath: custom.ini        

We mount the wordpress web log in persistent storage then changes persist on reboots. Nether this we add a new volumeMount and call it our config-book. This volition bear witness the path where this file is to exist mounted. The subPath option allows united states to utilize this configMap to have other configurations elsewhere in the pod.

The config-volume notwithstanding needs to reference the ConfigMap information technology is referring to, so we need the following:

          volumes:       - proper name: wordpress-persistent-storage         persistentVolumeClaim:           claimName: wp-pv-claim       - proper name: config-volume         configMap:           proper noun: custom-ini        

The persistentVolumeClaim was already there, merely underneath we add the configMap to reference the settings.

Now with a simple utilise nosotros tin can update the container. The container will reset just all changes volition still remain because nosotros utilize persistent volumes.

          kubectl apply -f custom-ini.yaml kubectl employ -f wordpress-deployment.yaml        

The changes should at present be seen in the new container if you log in and the user can now upload their behemothic themes.

harborhemat1949.blogspot.com

Source: https://benincosa.com/?p=3757

Postar um comentário for "Increase File Upload Size Ingress Ngnix Annotation"