Symfony4 Kubernetes Local Development Environment #3 Ksync

UPDATE: because of volume speed issues on OSX (and ksync not always smoothly working) and high CPU usage (1 2 3 …) when running Kubernetes locally I sadly cannot recommend k8s for local development atm. This article series was my exploration into if it’s feasible. If you have tips or suggestions please let me know. I’m running again on a docker-compose and Kubernetes combination.

Because of the investigated speed issued in part2 we will now install Ksync and set it up.

Git Repo

You can checkout branch part2 and apply the steps in this article yourself or checkout branch part3 where this has already been done and just play around.

Let’s start

These steps now are based on branch part2. Make sure our infrastructure is loaded using run/ We should see something like this:

Install Ksync.

curl | bash
ksync init # will install the necessary cluster server components

Now we run ksync watch in a separate terminal. I like to leave this open to see the output for debugging. We could also run ksync watch -d for daemon mode.

With ksync get we see configured sync processes and with ksync delete we can delete a single one or do ksync delete --all. Right now ksync get should show nothing, so let’s create one.

Show Ksync Log

The following command will show the last 20 logs and new ones coming in, so while configuring I like to leave this running.

kubectl logs `kubectl get pods -n kube-system | grep ksync | awk '{print $1;}'` -c syncthing -n kube-system -f --tail 20

Create folder sync

ksync create --selector=id=sf -c php $(pwd)/symfony /var/www/symfony

This will synchronize the local folder $(pwd)/symfony with the remote folder /var/www/symfony on the container php of each pod with label id=sf.

We see in the Ksync logs that a lot is happening, but if we ssh into our pod and php container we aren’t actually seeing any files. This is because Ksync and volumes sadly do not work together. So let’s remove the folder sync for now with ksync delete --all.

Adjust Kubernetes infrastructure

Apparently Ksync can’t sync if the remove directory is a Kubernetes volume, which we have currently configured. So we change our sf-deployment.yaml to something like this where I just commented out our volume handling:

Now we run run/ and run/ and create our folder sync again with:

ksync create --selector=id=sf -c php $(pwd)/symfony /var/www/symfony

Let’s check ksync get:

Nice. Watching at the Ksync log (as written above) there seems to be a lot of initial file syncing happening which might take some time to finish.

But calling http://localhost:80 in our browser results in the assets not being loaded and it looks like this:

Ksync assets to nginx container

To solve this we need to create a second sync of the public folder to our nginx container.

ksync create --selector=id=sf -c nginx $(pwd)/symfony/public /var/www/symfony/public

Once this run through ksync get should show:

Then our browser should show (maybe do a hard refresh):

Let’s make a code change!

I mean that’s why we do this in the first place! Let’s change something in the template main.html.twig , then check out logs and finally our browser.

For me it takes like ~one second to transfer the change. This is workable with. And we have almost local request times of ~20ms. Nice!

Visualize Ksync activity

(optional) We can also use the Ksync visualizer instead of checking the logs. For this run:

kubectl create -f

Wait for the container to be created, check for example with our run/ command. This might take a minute. Then run:

kubectl get po \
--selector=app=frontend \ \
--no-headers \
| xargs -IPOD kubectl port-forward POD 8081:80 &

And finally open http://localhost:8081/ in your browser. I am just seeing an empty page of a React App here though :) Maybe it works for you! Till then, I’ll stick to console logs!

You can remove it again like so:

kubectl delete -f

But this all seems so messy!

I know. Firstly there are so many commands to run! Let’s create a script for those at run/

Then we changed our Kubernetes infrastructure (removed the shared volume from our containers) just so we can run Ksync? Not cool! We will fix this in the next part when configuring Helm.


I can say it’s working and speed is ok. We have a script run/ which sets up synchronization.

But there is still a long initial sync which could be annoying. And we did have to change our Kubernetes config to make this running locally. We will solve this *hopefully* in the next part by using Helm.




-- | (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Quick & Dirty Object Detection(YOLO)

Why Google Cloud For Your M&E Workloads?

Configure Domain to Amazon EC2 with Amazon Route 53

Drivers Anatel Wn5301a-h1-v02

One Try Tee, 130. How I Loved and Hated Mathematics.

How To Learn Programming When You Don’t Know Where to Start

Zend Profitz Review

My journey becoming a Unity game developer: Make a game look beautiful-Putting up the walls to make…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kim Wuestkamp

Kim Wuestkamp | (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes

More from Medium

Learning note for Gitlab - Gitlab runner on Kubernetes

Get Started With Kubernetes!

8 ways to deploy managed Kubernetes cluster in Alibaba cloud

Setting up a Prometheus monitoring stack in Kubernetes