Skip to content

Commit

Permalink
Update README.md to remove outdated sections and improve clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
FLYBYME committed Jan 20, 2025
1 parent 9e93fb9 commit 402157f
Showing 1 changed file with 162 additions and 26 deletions.
188 changes: 162 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,174 @@
[![Moleculer](https://badgen.net/badge/Powered%20by/Moleculer/0e83cd)](https://moleculer.services)

# kubernetes
This is a [Moleculer](https://moleculer.services/)-based microservices project. Generated with the [Moleculer CLI](https://moleculer.services/docs/0.14/moleculer-cli.html).
# Kubernetes Service

## Usage
Start the project with `npm run dev` command.
After starting, open the http://localhost:3000/ URL in your browser.
On the welcome page you can test the generated services via API Gateway and check the nodes & services.
This service provides integration with Kubernetes clusters using the Moleculer framework. It allows you to manage and interact with Kubernetes resources programmatically.

## Features

- Load Kubernetes configurations
- Execute commands in Kubernetes pods
- Watch Kubernetes resources
- Manage Kubernetes resources through Moleculer actions

## Configuration

The service reads Kubernetes configurations from the `config` folder. Each configuration file should be named as `<cluster-name>.kubeconfig`.

## Actions

### loadKubeConfig

Load a Kubernetes configuration.

- **Params:**
- `name` (string): The name of the configuration.
- `kubeconfig` (string): The content of the kubeconfig file.

### exec

Execute a command in a Kubernetes pod.

- **Params:**
- `cluster` (string, optional): The name of the cluster. Default is 'default'.
- `namespace` (string): The namespace of the pod.
- `name` (string): The name of the pod.
- `container` (string, optional): The name of the container. If not provided, the first container in the pod will be used.
- `command` (array of strings): The command to execute.

### findOne

Find one document in the database.

- **Params:** Query parameters to filter the documents.

### find

Find documents in the database.

- **Params:** Query parameters to filter the documents.

## Methods

### loadKubeConfig

Load a Kubernetes configuration from a kubeconfig string.

- **Params:**
- `name` (string): The name of the configuration.
- `kubeconfig` (string): The content of the kubeconfig file.

### watchAPI

Watch a Kubernetes API for changes.

- **Params:**
- `config` (object): The Kubernetes configuration.
- `api` (string): The name of the API to watch.
- `events` (array of strings): The events to watch (default: ['ADDED', 'MODIFIED', 'DELETED']).

### loadApi

Load a Kubernetes API client.

- **Params:**
- `api` (string): The name of the API.
- `kc` (object): The Kubernetes configuration.

### watchResources

Watch all resources for a given configuration.

- **Params:**
- `config` (object): The Kubernetes configuration.

In the terminal, try the following commands:
- `nodes` - List all connected nodes.
- `actions` - List all registered service actions.
- `call greeter.hello` - Call the `greeter.hello` action.
- `call greeter.welcome --name John` - Call the `greeter.welcome` action with the `name` parameter.
### watchResource

Watch a specific resource for changes.

- **Params:**
- `api` (string): The name of the API.
- `client` (object): The Kubernetes API client.
- `watch` (object): The Kubernetes watch client.
- `config` (object): The Kubernetes configuration.

## Services
- **api**: API Gateway services
- **greeter**: Sample service with `hello` and `welcome` actions.
### loadKubeConfigs

Load all Kubernetes configurations from the config folder.

### stopWatching

Stop watching all resources.

### stopWatchingCluster

Stop watching resources for a specific cluster.

- **Params:**
- `cluster` (string): The name of the cluster.

### getClassMethods

Get all methods of a class.

- **Params:**
- `className` (object): The class to get methods from.

### parseArgs

Parse the arguments of a function.

- **Params:**
- `func` (function): The function to parse.

### flattenObject

Flatten an object.

- **Params:**
- `ob` (object): The object to flatten.

### findOne

Find one document in the database.

- **Params:**
- `query` (object): The query to filter the documents.

### find

Find documents in the database.

- **Params:**
- `query` (object): The query to filter the documents.

## Lifecycle Events

### created

Service created lifecycle event handler.

### started

Service started lifecycle event handler.

### stopped

Service stopped lifecycle event handler.

## Usage

To use this service, include it in your Moleculer project and configure it according to your needs. You can then call the actions provided by the service to interact with your Kubernetes clusters.

## Useful links
```javascript
const { ServiceBroker } = require("moleculer");
const KubernetesService = require("./services/kubernetes.service");

* Moleculer website: https://moleculer.services/
* Moleculer Documentation: https://moleculer.services/docs/0.14/
const broker = new ServiceBroker();

## NPM scripts
broker.createService(KubernetesService);

- `npm run dev`: Start development mode (load all services locally with hot-reload & REPL)
- `npm run start`: Start production mode (set `SERVICES` env variable to load certain services)
- `npm run cli`: Start a CLI and connect to production. Don't forget to set production namespace with `--ns` argument in script
- `npm run lint`: Run ESLint
- `npm run ci`: Run continuous test mode with watching
- `npm test`: Run tests & generate coverage report
- `npm run dc:up`: Start the stack with Docker Compose
- `npm run dc:down`: Stop the stack with Docker Compose
broker.start().then(() => {
// Call actions
broker.call("kubernetes.loadKubeConfig", { name: "default", kubeconfig: "..." });
});

0 comments on commit 402157f

Please sign in to comment.