# 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_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
}
kind: Pod
apiVersion: v1
metadata:
name: nginx-phpfpm
spec:
volumes:
# Create the shared files volume to be used in both pods
- name: shared-files
emptyDir: {}
# Add the ConfigMap we declared above as a volume for the pod
- name: nginx-config-volume
configMap:
name: nginx-config
For the same task, " kubectl get pods" shows always ‘ContainerCreating’ as shown below.
thor@jump_host /$ kubectl apply -f pod.yml
pod/nginx-phpfpm created
thor@jump_host /$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-phpfpm 0/2 ContainerCreating 0 8s
thor@jump_host /$
Any idea on this please?
@dushasokol Did you used same command (kubectl apply) to deploy the application?
As shown in below screenshot, PODs are running successfully. But Task got failed without mentioning any reasons. Can you please check what is the problem here. Thanks for your help.
I found why it fails. Verifying script try to connect to nginx and take “/” location, no “/index.php”. New config solve this. And i suppose authors need to fix task description.
how do you test this? after checking the pod is running, I use curl to test, but got forbidden error? is this ok for this task?
then i go in the pod, can’t find the /etc/nginx.conf file
@Inderpreet
the validation script might be a bug, I check the configuration, nginx and pod all in running state. can you mark this success for me - jenna
thank you.
lately, the lab environment is loading slow, including the kodekloud engineer and even in the kubernetes CKA course. Is there a way to speed the loading process? could be this cause the validation failed?
@dushasokol One thing that I don’t understand is why you used this:
I mean, I know this is the address this link uses, but I have used before this parameter with the unix socket like this fastcgi_pass unix:/var/run/php/php<YourPHPVersionHere>-fpm.sock; but that doesn’t work for me this time.
Can you explain me why the address works and the socket doesn’t work?
@dushasokol I am seeing “File not found” for curl cmd, as shown below. But index.php exists in /var/www/html
thor@jump_host /$ kubectl exec --stdin --tty nginx-phpfpm -- /bin/bash
Defaulting container name to php-fpm-container.
Use 'kubectl describe pod/nginx-phpfpm -n default' to see all of the containers in this pod.
root@nginx-phpfpm:/var/www/html# ls
root@nginx-phpfpm:/var/www/html# echo "<?phpinfo();?>" > index.php
root@nginx-phpfpm:/var/www/html# ls
index.php
root@nginx-phpfpm:/var/www/html# cat index.php
<?phpinfo();?>
root@nginx-phpfpm:/var/www/html# exit
exit
thor@jump_host /$ kubectl describe pod nginx-phpfpm | grep Ip
thor@jump_host /$ kubectl describe pod nginx-phpfpm | grep IP
IP: 10.44.0.1
IPs:
IP: 10.44.0.1
thor@jump_host /$ curl 10.44.0.1:8097
File not found.
thor@jump_host /$
Can you please guide me to fix this.
I tried following things:
Made sure proper permission for /var/www/html folder
I really have no idea. But I would check the “rootdir” in nginx.conf.
And also i would create “test.htm” and will make curl 10.44.0.1:8097/index.htm.
If it does not help me, i would redeploy pod without configmap and try to change config manually step-by-step from default to needed for me options
@balu.networks7 be careful, you are not specifying in which container to execute commands, so it is choosing the php-fpm-container, but you need to test in the web server container (the other)
Check docs on how to exec in a pod with multiple containers: