<p>I can provide a ubuntu with ssh by docker, and user can setup their env. 
For example, he apt-get install something and modify his bashrc, vimrc and so on.
Once I restart this computer, the user still has same env after restart finished.</p>

<p>How can I provide same service by k8s? 
Once I restart the node, it will create another pod on other computer. 
But the env is based on init image, not the latest env from the user.</p>

<p>The naive way, mount all volume on the shared storage(PV + PVC). Such as /bin /lib /opt /usr /etc /lib64 /root /var /home and so on(Each possible directory may effected by any installation). What is the best practice or other way to do this? </p>

<p>@Saket is Correct. </p>

<p>If a docker container needs to persist its state (in this case the user changing something inside the container), then that state must be saved somewhere... How would you do this with a VM? Answer: save to disk. </p>

<p>In k8s storage is represented as a persistent volume. Something called a PVC (persistent volume claim), is used to maintain the relationship between the POD (your code) and the actual storage volume (whose implementation details you are abstracted from). The latest version of k8s supports the dynamic creation of persistent volumes, so all you have to do is create a unique PVC specific to each user, when deploying their container (I assume here you have a "Deployment" and "Service" for each user as well).</p>

<p>In conclusion... Unusual to run SSH within a container. Have you considered giving each user their own k8s environment instead? For example <a href="https://www.openshift.org/" rel="nofollow noreferrer">Openshift</a> is multi-tenanted. Indeed Redhat are integrating Openshift as a backend for <a href="http://www.eclipse.org/che/" rel="nofollow noreferrer">Eclipse Che</a>, thereby running the entire IDE on k8s. See:</p>

<p><a href="https://openshift.io/" rel="nofollow noreferrer">https://openshift.io/</a></p>
