How to edit this Deployment Yaml to have write permission in container

4/14/2020

When i deploy this Deployment for sock-shop Yaml for sock-shop

but it does not give me write permission in the container so i cannot even write in it

$ kubectl exec -it carts-5496ffc4b6-5xr68 -n sock-shop -- sh
/usr/src/app $ apk add python
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied
/usr/src/app $ echo "Hello world" > sample.txt
sh: can't create sample.txt: Permission denied
/usr/src/app $ 
-- Pradeep Padmanaban
kubernetes

2 Answers

4/14/2020

You need to run the pod as root to be able to get that permission.Edit the yaml and add below in the carts deployment

securityContext:
  runAsUser: 0

Recommended option would be run apk add python in the Dockerfile itself and create a image with it installed already.

-- Arghya Sadhu
Source: StackOverflow

4/14/2020

In the Dockerfile of the container that runs the carts micro-service https://github.com/microservices-demo/carts/blob/master/Dockerfile , add the below line,

USER root

This will make sure root permission is added and apk add may work.

-- Aswin A.B.
Source: StackOverflow