kubernetes

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 14 Imported by: 24

README

Kubernetes Registry Plugin for micro

This is a plugin for go-micro that allows you to use Kubernetes as a registry.

Overview

This registry plugin makes use of Annotations and Labels on a Kubernetes pod to build a service discovery mechanism.

RBAC

If your Kubernetes cluster has RBAC enabled, a role and role binding will need to be created to allow this plugin to list and patch pods.

A cluster role can be used to specify the list and patch requirements, while a role binding per namespace can be used to apply the cluster role. The example RBAC configs below assume your Micro-based services are running in the test namespace, and the pods that contain the services are using the micro-services service account.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: micro-registry
rules:
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - list
  - patch
  - watch
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: micro-registry
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: micro-registry
subjects:
- kind: ServiceAccount
  name: micro-services
  namespace: test

Gotchas

  • Registering/Deregistering relies on the HOSTNAME Environment Variable, which inside a pod is the place where it can be retrieved from. (This needs improving)

Connecting to the Kubernetes API

Within a pod

If the --registry_address flag is omitted, the plugin will securely connect to the Kubernetes API using the pods "Service Account". No extra configuration is necessary.

Find out more about service accounts here. http://kubernetes.io/docs/user-guide/accessing-the-cluster/

Outside of Kubernetes

Some functions of the plugin should work, but its not been heavily tested. Currently no TLS support.

Documentation

Overview

Package kubernetes provides a kubernetes registry

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHostname   = errors.New("failed to get podname from HOSTNAME variable")
	ErrNoNodesFound = errors.New("you must provide at least one node")
)

Err are all package errors.

Functions

func NewRegistry

func NewRegistry(opts ...registry.Option) registry.Registry

NewRegistry creates a kubernetes registry.

Types

This section is empty.

Directories

Path Synopsis
Package client is the kubernetes registry client.
Package client is the kubernetes registry client.
api
Package api ...
Package api ...
mock
Package mock implements a mock k8s client.
Package mock implements a mock k8s client.
watch
Package watch implements the k8s watcher.
Package watch implements the k8s watcher.

Jump to

Keyboard shortcuts

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