how to use kubernetes http client to do what kubectl can do?

5/28/2020

I have built some docker images that can run some python jobs and spark jobs.

I can run them using kubectl in terminal to

  1. run it
  2. check the status of the job and
  3. get the log.
  4. get the instance count available from k8s
  5. get the instance type available from k8s.

I looked at the client libraries for Java and Golang. It does not seem the above 5 bullet points are supported or implemented there:

https://github.com/kubernetes-client/java

https://github.com/kubernetes-client/go

For example, here is a command I used on terminal to launch the spark job:

/Users/xyz/Documents/spark-2.4.5-bin-hadoop2.7/bin/spark-submit --class SimpleApp \
    --master "k8s://https://kubernetes.docker.internal:6443" \
    --deploy-mode cluster \
    --conf spark.kubernetes.container.image=sparkJob:latest \
    --conf spark.kubernetes.image.pullPolicy=IfNotPresent \
    --conf spark.executor.instances=1 \
    --conf spark.kubernetes.authenticate.driver.serviceAccountName=default \
    local:///small.jar

Getting the log from a pod in terminal with kubectl:

kubectl logs simpleapp-1580782281051-driver

I prefer not to invoke a shell to call kubectl from java/golang. I am looking for whether there exists an http client for it.

How can I do the same with k8s's java client or golang client as in kubectl?

-- cpchung
apache-spark
go
java
kubernetes

0 Answers