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: 3 months 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 (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-23T20:23:51.000Z (4 months ago)
- Last Synced: 2024-10-24T17:46:07.977Z (4 months 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
[](https://npmjs.com/package/@zcong/grpc-resolver-k8s)
[](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