Fix Issue with VolumeMounts in Kubernetes- failed

@rahul456

Can you please help me what is the error?

hor@jump_host ~$ kubectl get configmap nginx-config -o yaml
apiVersion: v1
data:
nginx.conf: |
events {
}
http {
server {
listen 8099 default_server;
listen [::]:8099 default_server;

    # Set nginx to serve files from the shared volume!
    root /var/www/html;
    index  index.html index.htm index.php;
    server_name _;
    location / {
      try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
      include fastcgi_params;
      fastcgi_param REQUEST_METHOD $request_method;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass 127.0.0.1:9000;
    }
  }
}

kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{“apiVersion”:“v1”,“data”:{“nginx.conf”:“events {\n}\nhttp {\n server {\n listen 8099 default_server;\n listen [::]:8099 default_server;\n\n # Set nginx to serve files from the shared volume!\n root /var/www/html;\n index index.html index.htm index.php;\n server_name _;\n location / {\n try_files $uri uri/ =404;\n }\n location ~ \\.php {\n include fastcgi_params;\n fastcgi_param REQUEST_METHOD $request_method;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi_pass 127.0.0.1:9000;\n }\n }\n}\n”},“kind”:“ConfigMap”,“metadata”:{“annotations”:{},“name”:“nginx-config”,“namespace”:“default”}}
creationTimestamp: “2020-11-29T17:20:11Z”
name: nginx-config
namespace: default
resourceVersion: “460”
selfLink: /api/v1/namespaces/default/configmaps/nginx-config
uid: 17a39da5-058f-44e0-b87c-4bb94f1da407

apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{“apiVersion”:“v1”,“kind”:“Pod”,“metadata”:{“annotations”:{},“name”:“nginx-phpfpm”,“namespace”:“default”},“spec”:{“containers”:[{“image”:“php:7.2-fpm”,“name”:“php-fpm-container”,“volumeMounts”:[{“mountPath”:"/var/www/html",“name”:“shared-files”}]},{“image”:“nginx:latest”,“name”:“nginx-container”,“volumeMounts”:[{“mountPath”:"/usr/share/nginx/html",“name”:“shared-files”},{“mountPath”:"/etc/nginx/nginx.conf",“name”:“nginx-config-volume”,“subPath”:“nginx.conf”}]}],“volumes”:[{“emptyDir”:{},“name”:“shared-files”},{“configMap”:{“name”:“nginx-config”},“name”:“nginx-config-volume”}]}}
creationTimestamp: “2020-11-29T17:20:11Z”
name: nginx-phpfpm
namespace: default
resourceVersion: “1144”
selfLink: /api/v1/namespaces/default/pods/nginx-phpfpm
uid: 5e9f8eb1-18a3-43b7-8ca4-9a722f148bd5
spec:
containers:

  • image: php:7.2-fpm
    imagePullPolicy: IfNotPresent
    name: php-fpm-container
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    • mountPath: /var/www/html
      name: shared-files
    • mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-z9crb
      readOnly: true
  • image: nginx:latest
    imagePullPolicy: Always
    name: nginx-container
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    • mountPath: /usr/share/nginx/html
      name: shared-files
    • mountPath: /etc/nginx/nginx.conf
      name: nginx-config-volume
      subPath: nginx.conf
    • mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-z9crb
      readOnly: true
      dnsPolicy: ClusterFirst
      enableServiceLinks: true
      nodeName: node01
      priority: 0
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: default
      serviceAccountName: default
      terminationGracePeriodSeconds: 30
      tolerations:
  • effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  • effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
    volumes:
  • emptyDir: {}
    name: shared-files
  • configMap:
    defaultMode: 420
    name: nginx-config
    name: nginx-config-volume
  • name: default-token-z9crb
    secret:
    defaultMode: 420
    secretName: default-token-z9crb
    status:
    conditions:
  • lastProbeTime: null
    lastTransitionTime: “2020-11-29T17:20:21Z”
    status: “True”
    type: Initialized
  • lastProbeTime: null
    lastTransitionTime: “2020-11-29T17:20:21Z”
    message: ‘containers with unready status: [php-fpm-container nginx-container]’
    reason: ContainersNotReady
    status: “False”
    type: Ready
  • lastProbeTime: null
    lastTransitionTime: “2020-11-29T17:20:21Z”
    message: ‘containers with unready status: [php-fpm-container nginx-container]’
    reason: ContainersNotReady
    status: “False”
    type: ContainersReady
  • lastProbeTime: null
    lastTransitionTime: “2020-11-29T17:20:21Z”
    status: “True”
    type: PodScheduled
    containerStatuses:
  • image: nginx:latest
    imageID: “”
    lastState: {}
    name: nginx-container
    ready: false
    restartCount: 0
    started: false
    state:
    waiting:
    message: Back-off pulling image “nginx:latest”
    reason: ImagePullBackOff
  • image: php:7.2-fpm
    imageID: “”
    lastState: {}
    name: php-fpm-container
    ready: false
    restartCount: 0
    started: false
    state:
    waiting:
    message: Back-off pulling image “php:7.2-fpm”
    reason: ImagePullBackOff
    hostIP: 172.17.0.49
    phase: Pending
    podIP: 10.88.0.4
    podIPs:
  • ip: 10.88.0.4
    qosClass: BestEffort
    startTime: “2020-11-29T17:20:21Z”

Hi,

The nginx config sets the document root to /var/www/html however the volume is mounted at /usr/share/www/html. Delete the pod and set the nginx-container volume mount to /var/www/html. Then copy the index.php file and curl localhost:8099 from the nginx-container. You should be able to view the php you copied. Good luck