<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>I've found a solution to my problem that's not common, I guess. I have to clarify that i'm not working on production environment. I just want to &quot;steal&quot; the source code from an image, since I don't have access to the repository.</p>
<p>Here is what I did:</p>
<p>1 . Created a folder and subfolder to organize the code.
2. Got a shell inside the pod's container:</p>
<pre><code>docker exec -it containername sh
</code></pre>
<p>or</p>
<pre><code>kubectl exec -it podsname -- sh

</code></pre>
<ol start="3">
<li>From the shell, edited what I wanted to edit in the source code.</li>
<li>Copied the content of the app folder IN THE CONTAINER to my local subfolder(called 'dados'):</li>
</ol>
<pre><code>cp -R /app /dados/
</code></pre>
<ol start="3">
<li>Created a Dockerfile in the folder that's based on the image I want to edit, then run a command to remove the /app folder, and finally, a command to copy the contents of my local folder to the new image I was going to build.</li>
</ol>
<pre><code>FROM kodekloud/examplevotingapp_vote:v1
RUN rm -rf /app/*.*
COPY ./dados/app /app
</code></pre>
<ol start="4">
<li>Created a new repository on DockerHub called 'myusername/my-voting-app' to receive my new image.</li>
<li>Built the new image:</li>
</ol>
<pre><code>docker build -t myusername/my-voting-app .
</code></pre>
<ol start="6">
<li>Tagged the image with my repo's name:</li>
</ol>
<pre><code>docker tag kaiohenricunha/my-voting-app kaiohenricunha/my-voting-app
</code></pre>
<ol start="7">
<li>Sent to dockerhub:</li>
</ol>
<pre><code>docker push kaiohenricunha/my-voting-app
</code></pre>
<ol start="8">
<li>Now on Kubernetes, changed my pod's container image to the new image I had built and deployed them.</li>
</ol>
