53/100 Resolve VolumeMounts Issue in Kubernetes
We encountered an issue with our Nginx and PHP-FPM setup on the Kubernetes cluster this morning, which halted its functionality. Investigate and rectify the issue:
The pod name is nginx-phpfpm and configmap name is nginx-config. Identify and fix the problem. Once resolved, copy /home/thor/index.php file from the jump host to the nginx-container within the nginx document root. After this, you should be able to access the website using Website button on the top bar.
# Check existing running pods:
thor@jumphost ~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-phpfpm 2/2 Running 0 2m28s
# Check the shared volume path in the existing config map
thor@jumphost ~$ kubectl get configmap
NAME DATA AGE
kube-root-ca.crt 1 5m2s
nginx-config 1 2m44 <-- This file
thor@jumphost ~$ kubectl describe configmap nginx-config
Name: nginx-config
Namespace: default
Labels: <none>
Annotations: <none>
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;
}
}
}
# Get the config yaml file from the running pod, save to tmp and review:
thor@jumphost ~$ kubectl get pod nginx-phpfpm -o yaml > /tmp/nginx.yaml
thor@jumphost ~$ cat /tmp/nginx.yaml
--Snipped --
volumeMounts:
- mountPath: /usr/share/nginx/html < this is incorrect should be /var/www/html
# Make revelant changes and then save file and post changes using force
thor@jumphost ~$ kubectl replace -f /tmp/nginx.yaml --force
pod "nginx-phpfpm" deleted
pod/nginx-phpfpm replaced
# Check pods running status time:
thor@jumphost ~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-phpfpm 2/2 Running 0 25s
# Copy the index.php from jump host to the nginx-container
thor@jumphost ~$ kubectl cp /home/thor/index.php nginx-phpfpm:/var/www/html -c nginx-container