k8s.io/client-go@v0.31.1/examples/out-of-cluster-client-configuration/README.md (about)

     1  # Authenticating outside the cluster
     2  
     3  This example shows you how to configure a client with client-go to authenticate
     4  to the Kubernetes API from an application running outside the Kubernetes
     5  cluster.
     6  
     7  You can use your kubeconfig file that contains the context information
     8  of your cluster to initialize a client. The kubeconfig file is also used
     9  by the `kubectl` command to authenticate to the clusters.
    10  
    11  ## Running this example
    12  
    13  Make sure your `kubectl` is configured and pointed to a cluster. Run
    14  `kubectl get nodes` to confirm.
    15  
    16  Run this application with:
    17  
    18      cd out-of-cluster-client-configuration
    19      go build -o app .
    20      ./app
    21  
    22  Running this application will use the kubeconfig file and then authenticate to the
    23  cluster, and print the number of pods in the cluster every 10 seconds:
    24  
    25      ./app
    26      There are 3 pods in the cluster
    27      There are 3 pods in the cluster
    28      There are 3 pods in the cluster
    29      ...
    30  
    31  Press <kbd>Ctrl</kbd>+<kbd>C</kbd> to quit this application.
    32  
    33  > **Note:** You can use the `-kubeconfig` option to use a different config file. By default
    34  this program picks up the default file used by kubectl (when `KUBECONFIG`
    35  environment variable is not set).