<p>I have deployed this using Kubernetes:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: voting-app-deploy
  labels:
    name: voting-app-deploy
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: voting-app-pod
      app: demo-voting-app
    
  template:
    metadata:
      name: voting-app-pod
      labels:
        name: voting-app-pod
        app: demo-voting-app
    spec:
      containers:
        - name: voting-app
          image: kodekloud/examplevotingapp_vote:v1
          ports:
            - containerPort: 80
</code></pre>
<p>With this Service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: voting-service
  labels:
    name: voting-service
    app: demo-voting-app
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30004
  selector:
    name: voting-app-pod
    app: demo-voting-app

</code></pre>
<p>After checking if the Pods are running, I get a shell to the running container where I can see the source code and make changes using vi:</p>
<pre><code>kubectl exec -it podsname -- sh
</code></pre>
<p>The problem is whenever I destroy the deployment and bring it back I lose all my changes in the source code.</p>
<p>This is the application's Dockerfile, which I got from within the running container:</p>
<pre><code># Using official python runtime base image
FROM python:2.7-alpine

# Set the application directory
WORKDIR /app

# Install our requirements.txt
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Copy our code from the current folder to /app inside the container
ADD . /app

# Make port 80 available for links and/or publish
EXPOSE 80

# Define our command to be run when launching the container
CMD [&quot;gunicorn&quot;, &quot;app:app&quot;, &quot;-b&quot;, &quot;0.0.0.0:80&quot;, &quot;--log-file&quot;, &quot;-&quot;, &quot;--access-logfile&quot;, &quot;-&quot;, &quot;--workers&quot;, &quot;4&quot;, &quot;--keep-alive&quot;, &quot;0&quot;]
</code></pre>
<p>So, how can I get this source code and generate a new image?</p>

Kaio H. Cunha
<p><strong>Quick and dirty</strong></p>
<p>If you change your code often and this isn't a production environment you can use the <code>--reload</code> that's according to <a href="https://stackoverflow.com/a/24893069/5459640">this</a> thread is available since gunicorn 19.0. this option makes the server reload your code changes into new workers.</p>
<p>Then when you want to save your new image you can use <code>docker commit</code> to &quot;commit&quot; or save your changes to a new image like so:</p>
<pre><code>docker commit running_container_name_or_id imagerepo/image-name:tag
</code></pre>
<p>Though this isn't that recommended in the long run just for small fixes and checks.</p>
<p><strong>Long term preferred usage</strong>
If you want a long term method method either develop locally with a mounted bind-mount (map a folder from the host machine to the docker container) and build a final image for kubernetes, or you could mount your source code using a config map like in this example:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: file-configmap
  namespace: default
data:
  config.conf: |
    [mysqld]
    binlog-format=mixed
</code></pre>
<p>Pod (usage in deployment is the same):</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: 
spec:
  containers:
    - name: container-name
      image: image-name
      volumeMounts:
      - name: my-file-volume
        mountPath: /path/in/container/config.conf
        subPath: config.conf
  volumes:
    - name: my-file-volume
      configMap:
        name: file-configmap
</code></pre>
