Start minikube with TTLAfterFinished flag:
minikube start --feature-gates=TTLAfterFinished=true
Switch to minio docker deamon:
eval $(minikube docker-env)
Apply manifests for namespace, application and service:
kubectl apply -f manifests/
Build docker image:
docker build -t kube-test:0.1 .
Tests run in the kubernetes cluster so they can access our service using DNS service name (http://hello.hello-ns.svc.cluster.local:8081
).
Apply manifests for the application, service and namespace. If you see the error you should try to apply it one more time. The issue is that namespace should be created before other resources will be created.
Set context:
kubectl config set-context --current --namespace=hello-ns
Build docker image in the docker deamon from Minikube:
eval $(minikube docker-env)
cd tests
docker build -t kube-test:0.1 .
Run tests as kubernetes job:
kubectl create -f tests/k8s/
Get logs from job:
kubectl logs $(kubectl get pods -l job-name --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
You should see:
Status code: 200
Check that job is completed successfully (status should be Complete
).
For failed tests it will have Failed
status.
kubectl get jobs --sort-by=.metadata.creationTimestamp -o jsonpath='{..items[-1:]..conditions[0].type}'
Change the host port to the wrong value: 8082
inside the test_smoke.py file, build the test again and see that job has Failed
status now.
make build-test
make test
kubectl get jobs --sort-by=.metadata.creationTimestamp -o jsonpath='{..items[-1:]..conditions[0].type}'
Clean mechanism for jobs docs
Job manifest has ttlSecondsAfterFinished setting which tell the k8s to delete job after the specified time (auto clean mechanism).
You can see the jobs and their statuses using minikube dashboard. Start minikube dashboard:
minikube dashboard
It will open the minikube dashboard in your current browser. Choose the hello-ns namespace there and open the jobs tab to see running jobs.
You can set up everything also using Makefile
make start-minikube
make deploy
make build-test
make test