K8s L1 last ques


→ i exec into container to check nginx document root and found the doc root to be /var/www/html
Then i copied the fiile from host to container using below command
kubectl cp /home/thor/index.php nginx-phpfpm:/var/www/html/ -c nginx-container

But i am not able to access the website. What should i do?

Also i am getting below error on copying file to container:

thor@jump_host ~$ k cp /home/thor/index.php nginx-phpfpm:/var/www/html -c nginx-container
tar: /var/www: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
command terminated with exit code 2

Unfortunately I am not able to jump to random tasks in KKE, so I can’t solve this directly.
The question says there is some issue to fix, before you upload the file. Did you find and fix the issue?

Pod is running and i cant see any error. i tried troubleshooting but cant find any error.

It points out a configmap, which is presumably the nginx config file. Is there any issue with that which may prevent nginx from serving the files correctly?

Also, is the configmap being correctly mounted?

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: "2023-09-07T19:18:52Z"
  name: nginx-config
  namespace: default
  resourceVersion: "1462"
  uid: b5bda7c4-984f-4822-8084-e1c03a1fa1cb

This is the cm yaml file. All the index files are present . Do i need to make index.htm to index.html or need to change port.

Is the listen port correct?
What is the message when you do try to access the website?

Also if you have uploaded the file and you exec inside the container, do you get anything sensible if you curl nginx on the port it is listening on, e.g.

curl localhost:8099

its showing 404 Not Found
svc is also using the same port 8099.
I was not able to copy files as its giving error
On curl its showing connection refused error.

thor@jump_host ~$ curl localhost:8099
curl: (7) Failed to connect to localhost port 8099: Connection refused

Not curl from jump host

kubectl exec nginx-phpfpm -c nginx-container -it -- /bin/sh

Then curl from the prompt inside the container

And the fact that it mentions nginx-container suggests there may be an initContainer or sidecar. Are these doing what they should?

I’ve asked the lab guys if there is a way for me to jump to specific task in KKE. If they can do that, then I can examine this task properly tomorrow.

1 Like
thor@jump_host ~$  k exec nginx-phpfpm -c nginx-container -it -- /bin/sh
# curl localhost:8099
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.25.2</center>
</body>
</html>

nginx-container should mount /var/www/html?

- 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: kube-api-access-gjr4b
      readOnly: true

is mounting /var/www/html same as mounting /etc/nginx/nginx.conf

nginx is serving, but cannot find an index page. Is this the same message you get when pressing the website button? If so, then the port is correct, but something else in the configuration is incorrect.

  • What files are in /var/www/html? It should serve any of index.html index.htm index.php directly to that curl if any are present.
  • Also if they are there, do they have read permissions for all?
  • Is this directory a volume mount in the pod definition? If so is it correctly mounted?

Refer also to the nginx documentation to understand any configuration directive you might not recognize.

I have to sign off now, but if I get access to the task, then I will solve it, if you haven’t already.

1 Like

Yes nginx is not able to dind index page and error is same.
i think there is some problem with mounting in pod nginx-container is not mounting /var/www/html

Would need to look at the volumes section too. The config volume should be mounting the configmap containing the configuration. Is the shared-files volume an emptyDir? Could be in that case it should be mounted on /var/www/html

However I really do have to go. I will check in on this sometime tomorrow