kubernetes-cluster-mock is a mock to a Kubernetes Cluster API using Flask. You can use it to test your application that integrates with Kubernetes API.
kubernetes-cluster-mock is available on dockerhub. To run it, just execute:
containerId=$(docker run -d -p 9988:9988 ezequielmr94/kubernetes-cluster-mock:latest)
docker cp $containerId:/root/kubernetes-cluster-mock/assets/config ./local_config
Inside the assets
folder you can find a kube config file to access the kubernetes-cluster-mock service.
You can copy it from the container too.
For now, you can:
- List Nodes
- Create a ingress
- List ingresses
- Delete a ingress
- Create a ingress using
kubectl create -f
- Create a pod
- List pods
- Delete a pod
- Create a pod using
kubectl create -f
- Create a deploy
- Deploy creating pods
- List deploys
- Delete a deploy
- Create a deploy using
kubectl create -f
You can manually change the status of a pod using the route bellow:
POST - "/custom_routes/change_pod_phase/<namespace>/<pod_name>/<phase>"
Example:
import requests
requests.post("http://localhost:9988/custom_routes/change_pod_phase/production/pod-1/Pending")
You can manually change cluster size:
POST - "/custom_routes/change_cluster_size/<new_size>"
Example:
import requests
requests.post("http://localhost:9988/custom_routes/change_cluster_size/2")
You also should use virtualenv to build/develop the project and I recommend the use of pyenv with pyenv-virtualenv to manage multiple python environments.
pyenv install 3.7.5
pyenv virtualenv 3.7.5 kubernetes-cluster-emulator
Open your bash and run the follow command to install all the project dependencies, you just need to run the command one time
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
Building the docker file:
docker build . -t ezequielmr94/kubernetes-cluster-mock:latest
Uploading the image to the repository:
docker push ezequielmr94/kubernetes-cluster-mock:latest
Pull the latest version of the image:
docker pull ezequielmr94/kubernetes-cluster-mock:latest