🚀 Test your apps in disposable, prod-like Kubernetes clusters 🚀
[[ insert gif here when ready ]]
k8s-harness
is for you if:
k8s-harness
is probably not for you if:
k8s-harness
is simple:
.k8sharness
file.k8s-harness run
run
can take a long time depending on your network connection. If you want to see more
details behind what's going on, enable debug output like this:
$: k8s-harness --debug run
or this:
$: LOG_LEVEL=debug k8s-harness run
Here's how it really works:
k8s-harness
will look for a .k8sharness
file in the root of your repository,k8s-harness
will also provision a local insecure Docker registry into which you can pushk8s-harness
will run your tests as defined by .k8sharness
in a Bash subshell,k8s-harness
destroys the cluster (unless you keep it up with --disable-teardown
).(If you're interested in the nitty-gritty of how k8s-harness
works, check out
its tests for the details.)
k8s-harness
uses .k8sharness
files to determine what it should do once its cluster is
provisioned. An example file is provided at .k8sharness.example
,
but the crux of how it works is this:
Define your test like this:
test: make test
You can optionally add setup or teardown instructions too:
test: make test
setup: helm install -f testenv.yaml
teardown: make report
Every command in test
, setup
, and teardown
runs in a sh
subshell, but you can
provide a script as well:
test: make test
setup: helm install -f testenv.yaml
teardown: ./scripts/run_teardown.sh
If you need to have more control over the subshell, just start your test command with
sh -c
:
test: make test
setup: helm install -f testenv.yaml
teardown: sh -xc "echo 'I\'m gonna wreck it!'"
gem install k8s-harness
if you're installing this standalone, ork8s-harness
into your app's Gemfile
if you're building a Ruby or Rails app..k8sharness.example
.k8sharness
file.k8s-harness --help
to learn how to configure k8s-harness
to your liking.Nope! Docker Compose is excellent for locally running your apps and testing that your app
works in Docker. However, I've found Compose to be lacking for testing whether my app can run
with Kubernete's extra features, like Secret
s and Ingress
objects. As well, for writing
Ansible playbooks that provision "hard" Kuberntes infrastructure like installing CRDs, I've found
having clean Kubernetes clusters that resemble what I'm provisioning in production to be fast
(or at least faster than waiting for CI/CD to apply my manifests) and cost-effective (since
I don't need to provision my own Kubernetes clusters externally).
$x
. How do I install $x
in k8s-harness?This is not supported yet, but is on the roadmap!
Thanks for helping make k8s-harness
better!
Contributing is simple.
Fork this repository.
Add a test in tests/
.
NOTE: If you're adding a new feature to k8s-harness
, you'll also need to add
an integration test in tests/integration
to describe what the feature does, how users
should use it, and what they can expect when it runs.
See the integration test for run
for an example.
Add your code in lib
.
Run your unit tests: make unit
Run the integration test to ensure that everything works: make integration
Push your commits up to your fork, then submit a new pull request into this repo!
You're free to fork this and create your own gems from a forked instance of this codebase. Note
that the CD that's included in the .github
directory requires that you
define GEM_HOST_API_KEY
in your build.