Edit a File in a Running Kubernetes Pod: a Simple Case
Premium Challenge
Upgrade your membership to unlock this and all other premium materials.
There is a Pod called web-server in the default namespace.
Its only container is called app and runs a simple web server that serves static files from the /var/www/html directory on port 8080.
Your task is to edit the /var/www/html/index.html file in this container without restarting the app container or recreating the Pod:
- Replace the phrase "Hello World" with the phrase "Hello Labs".
- Add the phrase "Practice for the win!" anywhere in the file.
To see the current page, send a request to the Pod's IP address on port 8080:
POD_IP=$(kubectl get pod web-server -o jsonpath='{.status.podIP}')
curl ${POD_IP}:8080
Hint 1
The container image has a shell and the usual command-line editing tools (e.g., sed).
The kubectl exec command can run any of them inside the container.
Hint 2
If you prefer to edit the file with the tools on your machine,
the kubectl cp command can copy a file from a Pod and copy it back.
Check kubectl cp --help for the source and destination format.