Files
client-go/examples/out-of-cluster
Ahmet Alp Balkan 11c69ac127 clientgo/examples/out-of-cluster: add instructions
Adding instructions for out-of-cluster example and making it work without
specifying the -kubeconfig argument if the home directory can be inferred.

This is part of the body of work improving the client library samples.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>

Kubernetes-commit: e59f05fe0ee6980c4bdaae76f5a77ef884bd2da1
2017-06-13 20:38:46 +00:00
..
2017-04-15 20:28:18 +00:00

Authenticating outside the cluster

This example shows you how to authenticate to the Kubernetes API from an application running outside the Kubernetes cluster with client-go.

You can use your kubeconfig file that contains the context information of your cluster to initialize a client. The kubeconfig file is also used by the kubectl command to authenticate to the clusters.

Running this example

Make sure your kubectl is configured and pointed to a cluster. Run kubectl get nodes to confirm.

Run this application with:

cd out-of-cluster
go build -o app .
./app

Running this application will use the kubeconfig file and then authenticate to the cluster, and print the number of nodes in the cluster every 10 seconds:

$ ./app
There are 3 pods in the cluster
There are 3 pods in the cluster
There are 3 pods in the cluster
...

Press Ctrl+C to quit this application.

Note: You can use the -kubeconfig option to use a different config file. By default this program picks up the default file used by kubectl (when KUBECONFIG environment variable is not set).