Categorygithub.com/devexps/go-micro/registry/k8s/v2
modulepackage
2.0.7
Repository: https://github.com/devexps/go-micro.git
Documentation: pkg.go.dev

# README

Note

Defines the key name of specific fields

GoMicro needs to cooperate with the following fields to run properly on kubernetes:

  • gomicro-service-id: define the ID of the service
  • gomicro-service-app: define the name of the service
  • gomicro-service-version: define the version of the service
  • gomicro-service-metadata: define the metadata of the service
  • gomicro-service-protocols: define the protocols of the service

Example Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: shop_api
  labels:
    app: shop_api
spec:
  replicas: 2
  selector:
    matchLabels:
      app: shop_api
  template:
    metadata:
      labels:
        app: shop_api
        gomicro-service-id: "56991810-c77f-4a95-8190-393efa9c1a61"
        gomicro-service-app: "shop_api"
        gomicro-service-version: "v1.0.0"
      annotations:
        gomicro-service-protocols: |
          {"8080": "http"}
        gomicro-service-metadata: |
          {"region": "sh", "zone": "sh001", "cluster": "pd"}
    spec:
      containers:
        - name: shop_api
          image: shop_api:1.0.0
          ports:
            - containerPort: 8080

# Functions

GetNamespace is used to get the namespace of the Pod where the current container is located.
GetPodName is used to get the name of the Pod where the current container is located.
LoadNamespace is used to get the current namespace from the file.
NewIterator is used to initialize Iterator.
NewRegistry is used to initialize the Registry.

# Constants

AnnotationsKeyMetadata is used to define the metadata of the service.
AnnotationsKeyProtocolMap is used to define the protocols of the service Through the value of this field, GoMicro can obtain the application layer protocol corresponding to the port Example value: {"8080": "http", "9090": "grpc"}.
LabelsKeyServiceID is used to define the ID of the service.
LabelsKeyServiceName is used to define the name of the service.
LabelsKeyServiceVersion is used to define the version of the service.
ServiceAccountNamespacePath defines the location of the namespace file.

# Variables

ErrIteratorClosed defines the error that the iterator is closed.

# Structs

ErrorHandleResource defines the error that cannot handle K8S resources normally.
Iterator performs the conversion from channel to iterator It reads the latest changes from the `chan []*registry.ServiceInstance` And the outside can sense the closure of Iterator through stopCh.
The Registry simply implements service discovery based on Kubernetes.