How do you put your source code in Kubernetes?

I'm new to Kubernetes, and so I wonder what recommendations are best used to add the application source code to a container in Kubernetes or a similar environment?

My application is PHP, so I have PHP (fpm) and Nginx containers (powered by Google Container Engine)

At first I had a git volume, but it was not possible to change such versions of applications, so I switched to emptyDir and installed the source code in a zip archive on one of the images that will unzip it to this volume after the start and now I have the source code , separate on both images via git with a separate git directory, so I have / app and / app-git.

This is good because I donโ€™t need to exchange or configure volumes (less resources and configuration), the application layer is reused in both images, therefore there is no effect on the space and since it is git, the โ€œbaseโ€ is built-in so I can simply configure the dockerfile command at the end and easily switch to another branch or tag.

I wanted to download the source archive directly from the repository, providing credentials as arguments during the build process, but that didnโ€™t work because my repo, bitpack, creates archives with the last commit identifier added to the directory, so there was no way knowing what will lead to unpacking the archive, so I'm stuck in git itself.

What are your ways of handling source code?

+6
source share
3 answers

Ideally, you should use continuous delivery templates, which means using Travis CI, Bitbucket pipelines or Jenkins to create the image when the code changes.

that is, every time your code changes, your automatic build will run and create a new Docker image that will contain your source code. You can then start the deployment deployment update to update the Pods with a new image.

If you have dynamic content, you are likely to put this persistent storage, which will be re-mounted when updating Pod.

+1
source

What we have traditionally done with PHP is the runtime overlay. Basically, the container will have the volume installed on it using the deployment keys for your git repository. This will allow you to perform git pull operations.

A more zipped approach is to have custom, tagged images of your code expand with fpm or whatever image you use. This way you will launch version 1.3 of your device, where YourImage will contain version 1.3 of your application.

0
source

Try to use continuous integration and continuous deployment. You can use Jenkins as a CI / CD server and create some tasks to create an image, click an image, and deploy an image.

I recommend putting the source code in a docker image instead of git repo. You can also extract configuration files from docker images. In kubernetes v1.2, it provides a new "ConfigMap" function, so we can put the configuration files in ConfigMap. When the container starts, the configuration files will be installed automatically. It is very comfortable.

0
source

Source: https://habr.com/ru/post/1012909/


All Articles