js-kube-client
v0.2.1
Published
A javascript client for Kubernetes API
Downloads
7
Maintainers
Readme
js-kube-client
A Javascript client dedicated to in-cluster Kubernetes jobs
Description
For those wanting to use Nodejs to interface Kubernetes API, here is been developed an API using native nodejs modules, to be used as deployment that manages jobs.
Prerequisites
- nodejs 12.x +
- docker 18.x +
- kubernetes 1.17.0 (checked)
Build a docker container
- Install docker https://docs.docker.com/install/ and build image:
docker build -t gh3s/js-kube-client -f build/Dockerfile .
- Install kubernetes https://kubernetes.io/docs/setup/
Testing using local server
- Delete 'cluster' in index.js.
const deployment = new Deployment('cluster')
const cronjob = new CronJob('cluster')
- Start server
npm start test <port>
cluster is a string for in-cluster appliances, default is for test purposes
- Deploy a test deployment in your cluster and test the code:
apply -f test/testjob.yaml
- Wait the job starts and search for it.
curl localhost:<port>/job?name=pi-with-ttl
Run in Kubernetes
- Apply the deployment.yaml:
kubectl apply -f kubernetes/deployment.yaml
- Apply service.yaml:
kubectl apply -f kubernetes/service.yaml
- Create a job using a POST request to
<nodeip>:<nodeport>
where<nodeip>
is a worker node IP. Use this JSON data for test purposes:
const jobYaml = {
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "pi-with-ttl"
},
"spec": {
"ttlSecondsAfterFinished": 10,
"template": {
"spec": {
"containers": [{
"name": "pi",
"image": "perl",
"command": [
"perl",
"-Mbignum=bpi",
"-wle",
"print bpi(2000)"
]
}],
"restartPolicy": "Never"
}
}
}
}
Verify the job with a GET request to
<nodeip>:<nodeport>/job?name=pi-with-ttl
Delete the job with a DELETE request to the same address.
NOTES:
For minikube testing:
minikube service --url js-kube-client
For GKE consider RBAC yaml file inside kubernetes folder
To update bundle
Update version in:
kubernetes/deployment.yaml
build/Dockerfile
package.json using 'npm init'
commit modifications and push to remote
publish npm
push to dockerhub
Release History
- 0.0.1
- CHANGE: Work in progress
- 0.0.3
- ADDED: Deployments and cronjobs
- 0.0.5
- ADDED: Persistent volumes and Persistent volume claims
- 0.1.0
- UPDATE: Security faults corrected
- 0.1.1
- ADDED: GKE RBAC yaml file
- 0.2.1
- UPDATE: Security faults corrected
- UPDATE: 4crud updated
Authors
- GH3S - Initial work - [email protected]
License
This project is licensed under the MIT License - see the LICENSE file for details
Contributing
- Fork it (https://github.com/gh3s/js-kube-client/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request