'Deploying Application code in Persisted Volume in Kubernetes

I am new to Kuberentes and am trying to deploying a simple webapp in it, currently I am building an image with all the dependencies and my application bundled in , uploading the image to repo and then deploying it in the pod, but the issue with this approach is that if I just want to edit my application code (let's say to add a print statement) I would need again build the image , upload it to repo and deploy it in K8.

Can I use the PVC to host my application code and refer it in my init container , is this a standard practice ?



Solution 1:[1]

Technically, you can. Practically, as far as I know, it is never a standard practice.

  • Majority of PVC solutions are ReadWriteOnce. So it would mean that you can't use scaling feature - replicas. You can't duplicate code easily across pods.

  • PVC is usually used for dynamic data: files or database - you separate code and configuration from data using PVC

  • Some images detect when there is nothing in PVC so app can be reinitialised from scratch, for example: prometheus, mysql and so on

  • PVC could be slower than data in Docker image (clustering mechanisms behind PVC)

  • If you have your code in PVC, you can't use anything app code related in Docker build phase (some testing, libraries resolution, etc.)

  • Pipeline may move away from standards (apps are usually built and deployed in a pipeline in Kubernetes)

  • and other consistency issues could occur

In case you need to edit code in development environment, other methods are used:

  • Locally, you can mount your local app folder to folder on Docker container, for instance it's volumes feature in Docker

  • Use minikube to recreate all containers locally for convenient development

  • Use tools to attach to containers such as https://code.visualstudio.com/docs/remote/attach-container

There should be a lot more methods, but you haven't mentioned the reason why building image with code is an issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 laimison