<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ori Hoch on Medium]]></title>
        <description><![CDATA[Stories by Ori Hoch on Medium]]></description>
        <link>https://medium.com/@orihoch?source=rss-d3361e01057c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*koGBtkOgf0WbWQPJ.</url>
            <title>Stories by Ori Hoch on Medium</title>
            <link>https://medium.com/@orihoch?source=rss-d3361e01057c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 23:08:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@orihoch/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Migrating a monolithic / legacy app and DB to Docker and Kubernetes]]></title>
            <link>https://faun.pub/migrating-a-monolithic-legacy-app-and-db-to-docker-and-kubernetes-efb314af6656?source=rss-d3361e01057c------2</link>
            <guid isPermaLink="false">https://medium.com/p/efb314af6656</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Ori Hoch]]></dc:creator>
            <pubDate>Thu, 18 Jan 2018 12:48:15 GMT</pubDate>
            <atom:updated>2019-07-16T14:42:03.860Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*6BiX91EsMc3EZfhDrBCDCg.png" /></figure><p>Step-by-step retrospective and relevant code allowing to replicate this method to migrate legacy / monolithic apps to Docker and Kubernetes.</p><p>All the code referred to in this guide is open source in the following repositories:</p><ul><li>The Midburn Kubernetes Environment — <a href="https://github.com/Midburn/midburn-k8s">https://github.com/Midburn/midburn-k8s</a></li><li>The monolithic app Dockerfiles and other code written in this method — <a href="https://github.com/orihoch/midburn-profiles-drupal">https://github.com/orihoch/midburn-profiles-drupal</a> (doesn’t contain the app itself which is closed-sourced at the moment)</li></ul><h3>Introduction</h3><p><a href="https://midburn.org/en/">Midburn</a> is a regional Burning Man event in Israel, it was the 2nd largest regional event in 2017 with 11,000 attendees.</p><p>We also have an active tech team which provides services to help manage this event, things like ticketing, camps and volunteers management and all other tech requirements.</p><h3>The monolithic app</h3><p>Among the apps Midburn tech maintains is a a Drupal based environment which handles many core services which most other services depend on.</p><p>This drupal environment is monolithic in several ways:</p><ul><li>It’s all installed manually on a single m4.xlarge AWS EC2 instance</li><li>The code is only available on the server and there is no clear distinction between the code, configuration and data.</li><li>The DB is highly dependant on the code / configuration — for example, an installation of a Drupal module makes changes to the DB and configuration.</li><li>It contains a lot of historical and unrelated data, hard to differentiate from the relevant data.</li><li>Making changes requires specific knowledge few people posses.</li></ul><p>This monolithic architecture is hard to maintain in the long-term because it makes it very hard and risky to make changes.</p><h3>The solution</h3><p>Docker and Kubernetes are great tools that enable to provide a quick solution for this monolithic app which solves many of the problems.</p><p>You can see the end result -</p><ul><li><a href="https://github.com/Midburn/midburn-k8s/tree/master/charts-external/profiles/templates">Midburn Profiles Helm Chart</a> — deployed as part of the <a href="https://github.com/Midburn/midburn-k8s">Midburn Kubernetes Environment</a> — allows anyone to view and suggest changes to the infrastructure.</li><li>Each environment’s configuration values are also available to view and suggest changes to using each environment’s <a href="https://github.com/Midburn/midburn-k8s/tree/master/environments/staging">values.yaml files</a></li><li><a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/docker-compose.yaml">Docker compose environment</a> allows to make changes and test locally</li></ul><h3>Download the server data</h3><p>Poking around in the server reveals 3 directories where the code / configurations are stored. I used google cloud storage to dump all the relevant data from the server.</p><p>It’s easy to install the gcloud tools on the server using either the <a href="https://cloud.google.com/sdk/downloads#yum">yum</a> or <a href="https://cloud.google.com/sdk/downloads#apt-get">apt-get</a> methods. Once you have gcloud tools installed you can login and copy the data to the cloud</p><blockquote>$ ssh -i secret.pem ubuntu@1.2.3.4 <br>:~$ gcloud auth login <br>:~$ gcloud config set project GOOGLE_PROJECT_ID<br>:~$ DATE=$(date +%Y-%m-%d)<br>:~$ gsutil -qm cp -cUPR /etc gs://bucket-name/profiles-etc-dump-${DATE}/</blockquote><ul><li>-q: quiet, otherwise it outputs every copied file</li><li>-m: allow to copy in parallel</li><li>-c: continue in case of errors</li><li>-U: skip unhandled file types</li><li>-P: preserve posix attributes</li><li>-R: recursive</li></ul><p>One more thing we need from this server is to figure out which distribution it is and which system dependencies are needed. We will replicate them in our Dockerfile.</p><h3>Create the server container</h3><p>In this case it was easy as they used a distribution that installed all requirements locally so we just need figure out the distribution, in this case Ubuntu Trusty.</p><p>You can see the full Dockerfile <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/Dockerfile">here</a></p><blockquote>FROM ubuntu:trusty</blockquote><p>Install gcloud and copy the downloaded data</p><blockquote>RUN apt-get update &amp;&amp; apt-get install -y curl &amp;&amp;\<br>export CLOUD_SDK_REPO=”cloud-sdk-$(lsb_release -c -s)” &amp;&amp;\<br>echo “deb <a href="http://packages.cloud.google.com/apt">http://packages.cloud.google.com/apt</a> $CLOUD_SDK_REPO main” | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list &amp;&amp;\<br>curl <a href="https://packages.cloud.google.com/apt/doc/apt-key.gpg">https://packages.cloud.google.com/apt/doc/apt-key.gpg</a> | sudo apt-key add — &amp;&amp;\<br>apt-get update &amp;&amp; apt-get install -y google-cloud-sdk</blockquote><blockquote>COPY secret-k8s-ops.json .</blockquote><blockquote>RUN gcloud auth activate-service-account — key-file=secret-k8s-ops.json;\<br>gcloud config set project midbarrn;\<br>addgroup — system — gid 1000 bitnami;\<br>adduser — system — uid 1000 — gid 1000 bitnami;\<br>mkdir -p /opt/bitnami;\<br>gsutil -qm cp -cUPR gs://midburn-k8s-backups/profiles-production-2018–01–16/etc /;\<br>gsutil -qm cp -cUPR gs://midburn-k8s-backups/profiles-production-2018–01–16/home/bitnami /home/;\<br>gsutil -qm cp -cUPR gs://midburn-k8s-backups/profiles-production-2018–01–16/opt/bitnami /opt/;\<br>rm -f secret-k8s-ops.json</blockquote><p>The files are private, so the docker build copies the secret google service account key file to download the files, then deletes it. It also sets correct permissions because we want to keep file ownership and permissions.</p><p>I use <a href="https://cloud.google.com/container-builder/">google cloud builder</a> and repository services to build and store the image privately.</p><blockquote>gcloud config project set PROJECT_ID<br>gcloud container builds submit -t gcr.io/PROJECT_ID/REPO_NAME:TAG .</blockquote><p>When done, pull the image</p><blockquote>gcloud docker ‘ — ‘ pull gcr.io/PROJECT_ID/REPO_NAME:TAG</blockquote><p>Check <a href="https://github.com/OriHoch/midburn-profiles-drupal">the repository</a> for a more advanced cloudbuild script and configuration</p><h3>Download the database dump</h3><blockquote>mysqldump “ — host=db” “ — port=3306” “ — protocol=tcp” “ — user=root” “ — password=${MYSQL_ROOT_PASSWORD}” “ — all-databases“ &gt; “dump.sql”</blockquote><p>Copy the dump to google storage</p><blockquote>gsutil cp dump.sql gs://bucket-name/db-dump-$(date +%Y-%m-%d)/</blockquote><h3>Create the database container</h3><p>Download the database dump</p><blockquote>gsutil cp gs://your-bucket/dump.sql ./dump.sql</blockquote><p>Run a DB server, mounting the dump file and the DB data directory locally</p><blockquote>docker run -d “ — name=mysql” \<br> -e MYSQL_ROOT_PASSWORD=123456 \<br>-v $(pwd)/dump.sql:/dump.sql \<br>-v $(pwd)/db:/var/lib/mysql \<br>mysql:5.6</blockquote><p>Import the DB dump data</p><blockquote>docker exec -it mysql bash<br>echo “create database midburndb;” | mysql — host=127.0.0.1 — user=root — password=123456<br>cat ./dump.sql | mysql — host=127.0.0.1 — user=root — password=123456 — one-database midburndb</blockquote><p>When mysql dump is done, copy the data directory to google storage</p><blockquote>gsutil -qm cp -PR ./db/ gs://bucket-name/db-data-dir/</blockquote><p>Now you can create the Dockerfile similar to the server Dockerfile which copies the data directory from google storage. You can see the full DB Dockerfile <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/db/Dockerfile">here</a>. It’s important to remember to copy the data to a directory which is <strong>not </strong>a volume, otherwise it will be empty or overwritten when the container starts.</p><h3>Run the environment</h3><p>I use docker compose to setup a local development / testing environment. You can see the full docker-compose.yml <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/docker-compose.yaml">here</a></p><p>Because the images contain private data, they are stored in the private google repository. You should pull them first using authenticated gcloud CLI</p><blockquote>gcloud docker — pull gcr.io/GOOGLE_PROJECT_ID/IMAGE_NAME:TAG</blockquote><p>start the environment</p><blockquote>docker-compose up</blockquote><h3>Making modifications and debugging locally</h3><p>When debugging locally, if you want to rebuild the image without re-downloading all the data dumps, you can comment out the download lines and just base the image on another image which has the data dumps. This is the in <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/Dockerfile#L20">the Dockerfile</a>.</p><p>When configured this way, to rebuild and re-run the local environment, just run:</p><blockquote>docker-compose up “—build”</blockquote><p>You can see in <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/Dockerfile#L20">the Dockerfile</a> some of the modifications I made —</p><ul><li>Modify configuration files — you can copy the original files from the data dumps or from the docker image. Then overwrite the files in the Dockerfile.</li><li>Added a docker entrypoint (see <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/entrypoint.sh">here</a>) which starts the required services, keeps the container running and outputs logs.</li></ul><p>When making these modifications the build completes locally in a few seconds (once you have the source images) allowing for very fast development and testing cycles.</p><p>The DB Image could be developed in the same way, in this case it was a simple Mysql DB, so not much else was needed.</p><h3>Deployment to Kubernetes</h3><p>You can see all the Kubernetes Helm templates <a href="https://github.com/Midburn/midburn-k8s/tree/master/charts-external/profiles/templates">here</a></p><p>Some notable features of these templates:</p><ul><li>The drupal pod uses a configmap to override a configuration file.</li><li>The DB pod allows to optionally provide an sql dump file to import from, instead of running the pre-populated image.</li></ul><h3>Continuous Deployment</h3><p>I use some templates and scripts I collect in <a href="https://github.com/OriHoch/sk8s/blob/master/README.md">sk8s</a>, which also depend on the main Midburn Kubernetes environment at <a href="https://github.com/Midburn/midburn-k8s">midburn-k8s</a>.</p><p>Check out the drupal app <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/.travis.yml">travis.yml</a> and <a href="https://github.com/OriHoch/midburn-profiles-drupal/blob/master/continuous_deployment.sh">continuous_deployment.sh</a> scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*l0djKxraJNJc2i7P" /></figure><p><strong>Join our community Slack and read our weekly Faun topics ⬇</strong></p><p><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmedium">Join a Community of Aspiring Developers.Get must-read articles, learn new technologies for free, chat with like-minded people, get job offers, listen to podcasts and more</a></p><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efb314af6656" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/migrating-a-monolithic-legacy-app-and-db-to-docker-and-kubernetes-efb314af6656">Migrating a monolithic / legacy app and DB to Docker and Kubernetes</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>