How to create general Kubernetes objects from yaml using Java client

10/9/2018

I want to create a service in Java which will take a yaml file and create whatever object is in there on a Kubernetes cluster.

Somewhat like how kubectl create -f file.yaml does.

The yaml file can contain a pod, service or deployment.

Can this be done in either official Kubernetes Java Client or fabric8 Kubernetes Java Client? How can it be achieved?

-- Piyush Shrivastava
java
kubernetes

1 Answer

10/9/2018

You can use Kubernetes REST API

Example create new deployment:

curl -X POST -d @deployment.json -H "Content-Type: application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" ${API}/apis/extensions/v1beta1/namespaces/${namespace}/deployments
-- Arslanbekov
Source: StackOverflow