How To Develop Applications On Local Kubernetes

How To Develop Applications On Local Kubernetes

Is your production running on Kubernetes?
Maybe you would like to run your applications on Kubernetes?
Or to test it out and see what is this Buzzword about?
If you are interested in K8S anyhow, you may benefit from running Kubernetes locally.

Kubernetes on your local machine. Why?

Let's start why having local Kubernetes is beneficial in the first place.

1. Having your local playground to learn

We, us developers need practical, safe experience, to actually get known with technology.
Having local Kubernetes allows us to set up, play and debug problems with comfort of our local machines.
If we break something, we break our own environment and in case of error we can always revert the previous state and try again with ease.

2. Testing before releasing it to production

So you have Kubernetes on production and you would like make a change in configuration. How do you test it?
We may be required to push changes, that we are not even sure they work, as we are unable to verify that.
We may push such untested changes to testing environment. However if we will break it, it will affect other people that use this environment.
And need to wait for the deployment to finish, each time we make a change.

Testing configuration on your local machine will be quicker and will be done in safer environment, and the safest is always your own environment.
After you will be sure, that configuration is correct you may push the changes and everyone around will be able to continue their work.

3. Running production like environment locally

Do you connect your applications using docker-compose locally and for the production you write Kubernetes configurations?

Docker have bring much more similarities between our production and local environments.
After running Docker on production, we still have gap, difference, which is execution platform for our docker containers.
The execution platform like Kubernetes, may be totally different than one you are running locally.
Running Kubernetes locally, decrease the gap to minimum. Now what we write for local configuration is going to be reused in the production.
This saves a lot of time for us, as write the configuration only once for all the environments.

How to set up Kubernetes locally?

Running Kubernetes cluster locally was simplified a lot due to supporting tools.
You may use MiniKube or Kind for example.

I have prepared step by step instruction for spinning your own Kubernetes Cluster Locally based on Kind and ctlptl.
You may follow this link to prepare your local environment.

After setting it up, you will be having Kubernetes Cluster that will allow you to
- deploy applications
- access applications using custom domains
- work under HTTPS locally.

Basically, you will be running your own small production.

I want to develop on my local Kubernetes

We need to distinguish two things.
One is to change K8S configuration and the second is to do development.

In case of the first one, we modify Kubernetes configurations (manifests) or docker images and deploy them to the cluster.
This is fine as long as we don't modify the code.

For PHP development or any other language, we want to change the code and see the results right away.

As deploying the application will take some time, this will not be the case.
Lucky, we have solution for that.

In case of code changes, we can synchronize the code to running application (Docker Container) instead of redeploying the whole application.
Skaffold is one of the tools that provide this way of working.

Skaffold in case we change Dockerfile or Kubernetes manifests will rebuild and redeploy the application and in case of code changes will simplify synchronize it to running application

Show me the Demo

If you want to see how it all play nicely together, you check Demo project based on PHP with Symfony and Ecotone that you can run on your own Kubernetes Cluster under Skaffold.

You will find it under this link.

> >