Skip to content

Instantly share code, notes, and snippets.

@growvv
Created June 12, 2022 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save growvv/dae1c7d99396a1c782e395f39845f6ed to your computer and use it in GitHub Desktop.
Save growvv/dae1c7d99396a1c782e395f39845f6ed to your computer and use it in GitHub Desktop.
Testing your K8s apps with KIND
#!/usr/bin/env bash
NAME="test-cluster"
echo "+++ Cleaning up old test artififacts"
kubectl delete cluster --name "${NAME}" > /dev/null 2>&1 || true
rm sample-controller > /dev/null 2>&1 || true
echo "+++ Creating test cluster"
kind create cluster --name "${NAME}" --config kind-config.yaml
export KUBECONFIG="$(kind get kubeconfig-path --name "${NAME}")"
echo "+++ Building sample controller"
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o sample-controller -ldfalgs
echo "+++ Building Docker image"
docker build -t sample-controller:test .
echo "+++ Loading image into kind container"
kind load docker-image --name "${NAME}" sample-controller:test
echo "+++ Deploying sample controller"
kubectl apply -f sample-controller.yaml
echo "+++ Deploying example foo resource"
kubectl apply -f example-foo.yaml
echo "+++ Testing environment is ready"
echo "+++ Run 'export KUBECONFIG=\"$(kind get kubeconfig-path --name "${NAME}")\"' to access the test cluster"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment