Prerequisites
Minikube should be installed (official guide or homebrew).
Let’s start it.
minikube start && kubectl proxy --port=8085
If you are working with multiple Kubernetes clusters, you may need to switch to the specific cluster you want to manage.
# Get the list of available clusters
kubectl config get-contexts
# Switch to desired cluster
kubectl config use-context minikube
And finally the test
curl http://localhost:8085/api/
{
"kind": "APIVersions",
"versions": [
"v1"
],
"serverAddressByClientCIDRs": [
{
"clientCIDR": "0.0.0.0/0",
"serverAddress": "192.168.49.2:8443"
}
]
}
Kubernetes Job API
Get jobs
curl --location --request GET 'http://localhost:8085/apis/batch/v1/namespaces/default/jobs/'
It is likely that when you perform this action, you will receive a response with an empty list of items, as there are no running jobs at the moment.
Let’s create a new job which calculates PI using a Perl docker image.
curl --location --request POST 'http://localhost:8085/apis/batch/v1/namespaces/default/jobs/' \
--header 'Content-Type: application/json' \
--data-raw '{
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "pi"
},
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "pi",
"image": "perl:5.34.0",
"command": ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"],
"env": []
}
],
"restartPolicy": "Never"
}
},
"backoffLimit": 4
}
}'
In order to check if the job is running quickly make a request to “GET Jobs” endpoints.