How to create and use a volume in kubernetes with the Go client API?

2/15/2017

What steps are needed to create and mount a local folder as a "persistent volume" in kubernetes, using the Go API?

(I'm using minikube, and trying to do the above, just to have some semi-persistent storage to play around with).

I have managed to define a Volume and VolumeMount in my JobSpec, for a Job that I can run successfully on minikube (see this code), but the volume does not seem to be properly created before referenced by the job in this way.

I started fleshing out some code for a spec of the container, which is commented out in my experiment code, as can be seen in this code, but I can't find where to send this volume specification, so that kubernetes will create it. Any hints?

-- Samuel Lampa
go
kubernetes
kubernetes-go-client

1 Answer

2/16/2017

Well, after I found out how to get error logs from the pods (1), I found the error (Calling bash, which didn't exist in the container image (only sh existed), and a typo in the mounted path).

Updated working code example available here.

(1) kubectl get pods to get pod id, and then kubectl logs <podid> to get the logs.

-- Samuel Lampa
Source: StackOverflow