Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcong1993/grpc-resolver-k8s
k8s resolver for @grpc/grpc-js
https://github.com/zcong1993/grpc-resolver-k8s
grpc grpc-node grpc-resolver k8s
Last synced: about 23 hours ago
JSON representation
k8s resolver for @grpc/grpc-js
- Host: GitHub
- URL: https://github.com/zcong1993/grpc-resolver-k8s
- Owner: zcong1993
- License: mit
- Created: 2021-09-13T03:25:00.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-23T20:23:51.000Z (15 days ago)
- Last Synced: 2024-10-24T17:46:07.977Z (15 days ago)
- Topics: grpc, grpc-node, grpc-resolver, k8s
- Language: TypeScript
- Homepage:
- Size: 293 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# grpc-resolver-k8s
[![NPM version](https://img.shields.io/npm/v/@zcong/grpc-resolver-k8s.svg?style=flat)](https://npmjs.com/package/@zcong/grpc-resolver-k8s)
[![NPM downloads](https://img.shields.io/npm/dm/@zcong/grpc-resolver-k8s.svg?style=flat)](https://npmjs.com/package/@zcong/grpc-resolver-k8s)> k8s resolver for @grpc/grpc-js
## Install
```bash
$ yarn add @zcong/grpc-resolver-k8s
# or npm
$ npm i @zcong/grpc-resolver-k8s --save
```## Usage
Make sure the client pod service account have enough permissions to access k8s resource endpoints. Can see [account.yaml](./example/k8s/account.yaml).
### client
```ts
import { K8sScheme, setup } from '@zcong/grpc-resolver-k8s'setup()
const serviceName = process.env.SERVICE_NAME || 'test-grpc-server'
const servicePort = process.env.SERVICE_PORT || '8080'
const serviceNs = process.env.SERVICE_NS || 'default'const main = async () => {
const c = new HelloClient(
`${K8sScheme}://${serviceNs}/${serviceName}:${servicePort}`, // use service name with K8sScheme
grpc.credentials.createInsecure(),
{ 'grpc.service_config': '{"loadBalancingConfig": [{"round_robin": {}}]}' } // don't forget use round_robin lb, default is pick first
)
}
```For more details, please check [example](./example).
### debug
Set env `GRPC_NODE_TRACE=k8s_resolver` and `GRPC_NODE_VERBOSITY=DEBUG`.
## License
MIT © zcong1993