Fix Issue with VolumeMounts in Kubernetes

Fix Issue with VolumeMounts in Kubernetes

Task :

We deployed a Nginx and PHPFPM based application on Kubernetes cluster last week and it had been working fine. This morning one of the team members made a change somewhere which caused some issues, and the application stopped working. Please look into the issue and fix it:

The pod name is nginx-phpfpm and configmap name is nginx-config, Nginx is running on port 8099. Figure out the issues and fix them.

Once you think issue is fixed copy /tmp/index.php from jump host to nginx-container under nginx document root and try to curl the nginx URL from nginx-container itself, you should be able to run the php page you copied. This step isn’t mandatory but it will be helpful to test the setup.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

Solution :

[email protected]_host /$ cd /home/thor/
[email protected]_host ~$ kubectl get configmap
NAME DATA AGE
nginx-config 1 70s
[email protected]_host ~$ kubectl get configmap nginx-config -o yaml > nginx-config.yml
[email protected]_host ~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-phpfpm 2/2 Running 0 101s
[email protected]_host ~$ kubectl get pod nginx-phpfpm -o yaml > nginx-phpfpm.yml
[email protected]_host ~$ vi nginx-phpfpm.yml

- image: nginx:latest
imagePullPolicy: Always
name: nginx-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/nginx/html
name: shared-files

change /usr/share/nginx/html to /var/www/html, according to docroot in configmap

- image: nginx:latest
imagePullPolicy: Always
name: nginx-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/www/html
name: shared-files

delete old pod, and create again

[email protected]_host ~$ kubectl delete pod nginx-phpfpm
pod "nginx-phpfpm" deleted
[email protected]_host ~$ kubectl apply -f nginx-phpfpm.yml 
pod/nginx-phpfpm created
[email protected]_host ~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-phpfpm 2/2 Running 0 7s

copy file /tmp/index.php tp /var/www/html inside container-based

[email protected]_host ~$ kubectl cp /tmp/index.php nginx-phpfpm:/var/www/html
Defaulting container name to php-fpm-container.

test curl from inside container

[email protected]_host ~$ kubectl exec --stdin --tty nginx-phpfpm -- /bin/sh
Defaulting container name to php-fpm-container.
Use 'kubectl describe pod/nginx-phpfpm -n default' to see all of the containers in this pod.
#curl http://localhost:8099/
#exit

Leave a Reply

Your email address will not be published. Required fields are marked *