Challenge Easy

Copy a File into a Running Pod to Serve a Custom NGINX Page

A Pod runs NGINX behind a NodePort Service. Copy an HTML page from dev-machine into the running Pod so NGINX serves it as the default page, without changing the Pod or the Service.

Scenario

A Pod named blackhole-3d runs an nginx container in the space namespace. The NodePort Service blackhole-3d-svc exposes it on port 30088, and the Blackhole-3D tab shows what NGINX currently serves: the default NGINX welcome page.

On dev-machine there is an HTML page with a simple 3D view of a black hole:

/home/laborant/blackhole/index.html

Task

Copy the black hole page from dev-machine into the running blackhole-3d Pod in the space namespace, so that NGINX serves it as its default page:

Path
Source (on dev-machine)/home/laborant/blackhole/index.html
Destination (in the nginx container of blackhole-3d)/usr/share/nginx/html/index.html

Then open the Blackhole-3D tab to see the page. If the tab still shows the old page, reload the playground page in your browser.

Important

Do not create, edit, or recreate the Pod or the Service. Copy the file into the Pod while it keeps running.


Hint 1: Copying into a running container

kubectl has a command that copies files between your machine and a container, without touching the Pod spec:

kubectl cp <local-path> <namespace>/<pod>:<path-in-container>

If a file already exists at the destination, it is replaced.

See: kubectl cp

Hint 2: Checking the result

Look at the file from inside the container:

kubectl exec -n <namespace> <pod> -- ls -l <directory>
kubectl exec -n <namespace> <pod> -- head -n 5 <file>

NGINX reads the file on every request, so there is nothing to restart.


⚒ Test Cases