12.12.17

Cobbling a kube/openshift client together

Since I'm not at red hat anymore, sometimes I have to ask my old friends for help.

When you first set out to write a kube/openshift app, you first look for an openshift-go client, and quickly find there isnt an obvious one that you can use.  A simple workaround: Use a kubernetes client.

My friend elmiko works on a project called https://github.com/radanalyticsio/oshinko-cli , which gives you openshift-native spark controllers.  So, anyways, here's how I got my native client app working...

0) Spin up an openshift cluster.  You can do this with minishift, but, if you want to run administrative API calls, it might be tricky. 

1) login with minishift, and save your kube/config file somewhere.  You'll be using it to authenticate to your cluster later.

2) Steal a good example of how to make an kube/openshift controller.

The client-go module for kubernetes has a few good examples, such as:

https://github.com/kubernetes/client-go/blob/master/examples/workqueue/main.go (for me, i renamed it worker.go)

3) Now, glide its dependencies into your local directory

glide init
glide update (maybe -v?)

4) Errors ? Substitute the "import" statements in the example main.go above with the Imports from https://github.com/radanalyticsio/oshinko-cli (just grep them out):

For example:

s

5) Rinse and repeat until no more glide import errors.

6) After that, you can go install your code, and run something like this:

$GOPATH/bin/worker --kubeconfig=/Users/jayunit100/.kube/config --master=https://12.234.56.789.xip.io:8443

The result -- you get a controller for free, and you can build your own kube/openshift apps that watch events, pods, and so on.

No comments:

Post a Comment