Created
June 12, 2022 11:24
-
-
Save growvv/dae1c7d99396a1c782e395f39845f6ed to your computer and use it in GitHub Desktop.
Testing your K8s apps with KIND
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
ref https://www.youtube.com/watch?v=8KtmevMFfxA&ab_channel=CNCF%5BCloudNativeComputingFoundation%5D