Skip to content

rajatgupta24/jx-kube-client

 
 

Repository files navigation

jx-kube-client

Go Report Card

Used to create a kubernetes client from within a Kubernetes cluster or outside using ~/.kube/config

Here's an example which also uses Jenkins X logging

import (
    "github.com/jenkins-x/jx-kube-client/v3/pkg/kubeclient"
    "github.com/jenkins-x/jx-logging/v3/pkg/log"
    "k8s.io/client-go/kubernetes"
)

func main() {
    f := kubeclient.NewFactory()
    cfg, err := f.CreateKubeConfig()
    if err != nil {
        log.Logger().Fatalf("failed to get kubernetes config: %v", err)
    }


    kubeClient, err := kubernetes.NewForConfig(cfg)
    if err != nil {
        log.Logger().Fatalf("error building kubernetes clientset: %v", err)
    }
}

To change the location of the kube config use the following instead:

    cfg, err := f.CreateKubeConfigFromCustomLocation(kubeConfigPath, kubeConfigFile)

Part of Jenkins X shared libraries.

About

Helper library to create a kubernetes client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 49.0%
  • Makefile 45.8%
  • Shell 4.7%
  • Dockerfile 0.5%