This project implements a mock Kubernetes API using the Fabric8 Mock Kubernetes Server. This allows an Octopus project to complete a real Kubernetes deployment without requiring a real Kubernetes cluster.
The mock server is embedded in an Octopus Container Image. The server is started when kubectl is called, and is destroyed once kubectl exits.
Because of this, the Kubernetes server appears to be blank with each step run by Octopus.
- URL:
http://localhost:48080 - Health Check Container Image:
octopussolutionsengineering/k8s-mockserverfrom a docker feed pointing toghcr.io.
- Add the
Octopus.Action.Container.Optionsvariable and set the value to-v /tmp:/tmp. This mounts the temporary directory of the worker into the container. - The mock server will return 200 OK for the endpoint
http://localhost:48080/healthif the file/tmp/onlineexists. If the file does not exist, it will return 500. - Steps can be added that check the return code of the endpoint
http://localhost:48080/healthto simulate a smoke test. These steps will succeed for fail based on the existence of the/tmp/onlinefile.
This is an example of a smoke test step that checks the health of the mock server:
CODE=$(curl --silent --output /dev/null --write-out "%{http_code}" "http://localhost:48080/health")
if [[ $CODE != "200" ]]
then
exit 1
fiThis is an example of a step that creates the online marker file:
touch /tmp/online- Container Image:
octopussolutionsengineering/k8s-mockserverfrom a docker feed pointing toghcr.io. Kubernetes Object Status Check:Don't do any verification checksServer-Side Apply:Use client-side apply
Create a Kubernetes configuration file with the contents:
apiVersion: v1
kind: Config
clusters:
- name: local
cluster:
server: http://localhost:48080
insecure-skip-tls-verify: true
contexts:
- name: local-context
context:
cluster: local
user: local-user
current-context: local-context
users:
- name: local-user
user:
username: admin
password: admin123Build the mock server with:
mvn clean package -DskipTestsRun the mock server with:
java -jar target/mockk8s.jarThen run kubectl commands against the mock server:
kubectl run nginx --image=nginxGet the list of pods:
kubectl get pods