Deploy Lamp Stack on Kubernetes Cluster - Task

Hi Team, I facing issue with one of the task " Deploying lamp server in Kubernetes cluster"

The Nautilus DevOps team want to deploy a PHP website on Kubernetes cluster. They are going to use Apache as a web server and Mysql for database. The team had already gathered the requirements and now they want to make this website live. Below you can find more details:

  1. Create a config map php-config for php.ini with variables_order = "EGPCS" data.

  2. Create a deployment named lamp-wp.

  3. Create two containers under it. First container must be httpd-php-container using image webdevops/php-apache:alpine-3-php7 and second container must be mysql-container from image mysql:5.6. Mount php-config configmap in httpd container at /opt/docker/etc/php/php.ini location.
    .
    .
    .
    etc

The issue is that, I am unable to create a pod with httpd contianer, it shows below error

Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting “/var/lib/kubelet/pods/73760fe7-53af-4200-a282-cc15b6a0eae9/volume-subpaths/config-volume/httpd-php-container/0” to rootfs at “/opt/docker/etc/php/php.ini”: mount /var/lib/kubelet/pods/73760fe7-53af-4200-a282-cc15b6a0eae9/volume-subpaths/config-volume/httpd-php-container/0:/opt/docker/etc/php/php.ini (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown

Here is the config file,

apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: lamp-wp
name: lamp-wp
spec:
replicas: 1
selector:
matchLabels:
app: lamp-wp
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: lamp-wp
spec:
volumes:
- name: config-volume
configMap:
name: php-config
containers:
- image: webdevops/php-apache:alpine-3-php7
name: httpd-php-container
volumeMounts:
- name: config-volume
mountPath: /opt/docker/etc/php/php.ini
- image: mysql:5.6
name: mysql-container
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:

  • name: MYSQL_PASSWORD
    valueFrom:
    secretKeyRef:
    name: mysecret
    key: mysql_password
    - name: MYSQL_DATABASE
    valueFrom:
    secretKeyRef:
    name: mysecret
    key: mysql_db
    - name: MYSQL_USER
    valueFrom:
    secretKeyRef:
    name: mysecret
    key: mysql_user
    - name: MYSQL_HOST
    valueFrom:
    secretKeyRef:
    name: mysecret
    key: mysql_host
    - name: MYSQL_ALLOW_EMPTY_PASSWORD
    valueFrom:
    secretKeyRef:
    name: mysecret
    key: mysql_allow_empty_password
    - name: MYSQL_RANDOM_ROOT_PASSWORD
    valueFrom:
    secretKeyRef:
    name: mysecret
    key: mysql_random_root_password
    resources: {}
    status: {}

Did I miss anything?

Appreciate the support as always, thanks!

@Hasil

Correction
mountPath: /opt/docker/etc/php

Note- The mount path in the container should be a directory, not a file.

Thanks @Jayendra-Darbar @Sauron
But now got different error,

Image: webdevops/php-apache:alpine-3-php7
Image ID: docker.io/webdevops/php-apache@sha256:bb68c986d4947d4cb49e2753a268e33ad3d69df29c8e9a7728090f4738d5bdb9
Port:
Host Port:
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Thu, 24 Aug 2023 11:08:04 +0000
Finished: Thu, 24 Aug 2023 11:08:04 +0000
Ready: False
Restart Count: 5
Environment Variables from:
mysecret Secret Optional: false
Environment:
Mounts:
/opt/docker/etc/php from php-ini (rw,path=“php.ini”)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-54wvk (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
php-ini:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: php-config
Optional: false
kube-api-access-54wvk:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional:
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message


Normal Scheduled 5m11s default-scheduler Successfully assigned default/lamp-wp-7bb964bd46-46wzn to kodekloud-control-plane
Normal Pulled 5m10s kubelet Container image “mysql:5.6” already present on machine
Normal Created 5m10s kubelet Created container mysql-container
Normal Started 5m9s kubelet Started container mysql-container
Normal Started 3m43s (x4 over 5m8s) kubelet Started container httpd-php-container
Warning BackOff 3m6s (x8 over 5m4s) kubelet Back-off restarting failed container httpd-php-container in pod lamp-wp-7bb964bd46-46wzn_default(15b37b1d-a440-43f3-aa77-835c999e029d)
Normal Pulled 2m52s (x5 over 5m9s) kubelet Container image “webdevops/php-apache:alpine-3-php7” already present on machine
Normal Created 2m51s (x5 over 5m9s) kubelet Created container httpd-php-container

kubectl logs lamp-wp-7bb964bd46-46wzn -c httpd-php-container
→ Executing /opt/docker/provision/entrypoint.d/05-permissions.sh
→ Executing /opt/docker/provision/entrypoint.d/20-php-fpm.sh
cp: can’t stat ‘/opt/docker/etc/php/fpm/php-fpm.conf’: No such file or directory
thor@jump_host ~$ k describe pod lamp-wp-7bb964bd46-46wzn

@Sauron well, I used subpath in the config
volumeMounts:
- name: php-ini
mountPath: /opt/docker/etc/php
subPath: php.ini

It is working

volumeMounts:

  • name: php-ini
    mountPath: /opt/docker/etc/php.ini
    subPath: php.ini

There is a fully worked solution to this question in this thread

Hi All, I thinks this one is little tricky. There are 2 traps there.

  1. Put variables_order = “EGPCS” into a configmap instead of php.ini with the content of variables_order = “EGPCS”
  2. volumeMount with subPath.