kubernetes

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 12 Imported by: 0

README

Kubernetes Config

Usage in the Kubernates Cluster

It is required to

serviceaccount should be set to the actual account of your environment, the default account will be namespace::default if the spec.serviceAccount is unset. execute this command:

kubectl create clusterrolebinding go-kratos:kube --clusterrole=view --serviceaccount=mesh:default

or use kubect apply -f bind-role.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: go-kratos:kube
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
- kind: ServiceAccount
  name: default
  namespace: mesh
Usage outside the Kubernates Cluster

Set the path ~/.kube/config to KubeConfig

    config.NewSource(SourceOption{
		Namespace:     "mesh",
		LabelSelector: "",
		KubeConfig:    filepath.Join(homedir.HomeDir(), ".kube", "config"),
	})

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSource

func NewSource(opts ...Option) config.Source

NewSource new a kubernetes config source.

Example
conf := config.New(
	config.WithSource(
		NewSource(
			Namespace("mesh"),
			LabelSelector("app=test"),
			KubeConfig(filepath.Join(homedir.HomeDir(), ".kube", "config")),
		),
	),
)
err := conf.Load()
if err != nil {
	log.Panic(err)
}
Output:

Types

type Option

type Option func(*options)

Option is kubernetes option.

func FieldSelector

func FieldSelector(field string) Option

FieldSelector with kubernetes field selector.

func KubeConfig

func KubeConfig(config string) Option

KubeConfig with kubernetes config.

func LabelSelector

func LabelSelector(label string) Option

LabelSelector with kubernetes label selector.

func Master

func Master(master string) Option

Master with kubernetes master.

func Namespace

func Namespace(ns string) Option

Namespace with kubernetes namespace.

Jump to

Keyboard shortcuts

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