How to provide a persistent ubuntu env by k8s

7/27/2017

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.

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.

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?

-- ChunTingLin
docker
kubernetes

2 Answers

7/27/2017

I would advise you to use ConfigMaps (https://github.com/kubernetes/kubernetes/blob/master/docs/design/configmap.md). This guide should help what you are trying to do: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-pod-environment-variables

Configmaps also allow you to store scripts, so you could have a .bashrc (or a section) stored in a confipmap.

-- Javier Salmeron
Source: StackOverflow

7/27/2017

@Saket is Correct.

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.

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).

In conclusion... Unusual to run SSH within a container. Have you considered giving each user their own k8s environment instead? For example Openshift is multi-tenanted. Indeed Redhat are integrating Openshift as a backend for Eclipse Che, thereby running the entire IDE on k8s. See:

https://openshift.io/

-- Mark O'Connor
Source: StackOverflow