Hello I am new to kubernetes. I am currently stuck trying to use a docker image from dockerhub were it is a php-fpm image. I would like to be able to customize the php.ini in a configmap how would I go about doing that. The image on dockerhub is crunchgeek/php-fpm and the instructions for php.ini say there is a environment variable "PHP_INI_PATH=/path/to/php.ini will include specified php.ini configuration during php-fpm manager start. It allows to use a wildcard in case you would like to include several .ini configuration files." How can I add a environment variable that controls the php.ini file to a configmap in kubernetes please a yaml example would help me so much thanks.
First you'll need to define the ConfigMap representing your php.ini
, something like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: php-ini-config
namespace: default
data:
php.ini: |
foo=bar
one=two
Then you can render this configmap into your workload as a volume, which looks something like this:
apiVersion: v1
kind: Pod
metadata:
name: test-pod
namespace: default
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "cat /etc/config/php.ini" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
env:
- name: PHP_INI_PATH
value: /etc/config/php.ini
volumes:
- name: config-volume
configMap:
name: php-ini-config
Notice in this YAML we also include the PHP_INI_PATH
environment variable pointing to the file under the volume, /etc/config/php.ini
.
In case you want to mount a configuration file of PHP .ini (creating a configmap from file) to your pod can do the following depends on if you're using helm or not.
When using helm you need to create a config map YAML file and put the desired configuration file (php.ini in your scenario) under a dedicated folder, (e.g conf folder) in the root of your helm Chart location, and then create a config map from that file and mount it to the deployment accordingly to your needs.
In case you are not using helm you can create the config map from a file directly using a kubectl command (took from this reference config map from file command):
create a config map from file with no helm:
kubectl create configmap phpini-configmap --from-file=configure-pod-container/configmap/php.ini
config map YAML when using helm would look similar to:
apiVersion: v1
kind: ConfigMap
metadata:
name: phpini-configmap
data:
php.ini: |-
{{ .Files.Get "conf/php.ini" | indent 4 }}
The pod should then consume this config map and mount it to the right path
apiVersion: v1
kind: Pod
metadata:
name: test-pod
namespace: default
spec:
containers:
- name: php-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "cat /etc/config/php.ini" ]
volumeMounts:
- name: ini-configmap
mountPath: /etc/config/php.ini
subPath: php.ini
env:
- name: PHP_INI_PATH
value: /etc/config/php.ini
volumes:
- name: ini-configmap
configMap:
name: phpini-configmap