k8s-client-go

module
v0.0.0-...-22d8ab2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2024 License: Apache-2.0

README

About

Minimal Go Kubernetes client based on Generics

Installing

go get github.com/EmilyShepherd/k8s-client-go

Usage

import (
    "context"
    "log"
    "fmt"
    client "github.com/EmilyShepherd/k8s-client-go"
)
func main() {
	kc, err := client.NewInCluster()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Backgroud()

	endpointsAPI := client.NewObjectAPI[corev1.Endpoints](kc)

	endpoints, err := endpointsAPI.Get(ctx, "kube-system", "kubelet", metav1.GetOptions{})
	if err != nil {
		// Handle err
		return
	}
	fmt.Printf("%+v\n", endpoints)

	events, err := endpointsAPI.Watch(ctx, "kube-system", "kubelet", metav1.ListOptions{})
	if err != nil {
		// Handle err
		return
	}
	for e := range events.ResultChan() {
		fmt.Printf("%s: %+v\n", e.Type, e.Object)
	}
}

See more in Examples

Use cases

  • Embedding in Go applications for minimal binary size overhead.
  • Service discovery by listing and watching endpoints. See kuberesolver as example for gRPC client side load balancing.

Directories

Path Synopsis
pkg
stream
Package stream implements a set of generic interfaces and classes designed to allow streams of atomic objects to be pipelined, much line one might do with an io.Reader
Package stream implements a set of generic interfaces and classes designed to allow streams of atomic objects to be pipelined, much line one might do with an io.Reader

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL