# shell-operator **Repository Path**: lshgdut/shell-operator ## Basic Information - **Project Name**: shell-operator - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-06-22 - **Last Updated**: 2024-07-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

Shell-operator logo

docker pull flant/shell-operator GH Discussions Telegram chat RU

**Shell-operator** is a tool for running event-driven scripts in a Kubernetes cluster. This operator is not an operator for a _particular software product_ such as `prometheus-operator` or `kafka-operator`. Shell-operator provides an integration layer between Kubernetes cluster events and shell scripts by treating scripts as hooks triggered by events. Think of it as an `operator-sdk` but for scripts. Shell-operator is used as a base for more advanced [addon-operator](https://github.com/flant/addon-operator) that supports Helm charts and value storages. Shell-operator provides: - __Ease of management of a Kubernetes cluster__: use the tools that Ops are familiar with. It can be bash, python, kubectl, etc. - __Kubernetes object events__: hook can be triggered by `add`, `update` or `delete` events. **[Learn more](HOOKS.md) about hooks.** - __Object selector and properties filter__: shell-operator can monitor a particular set of objects and detect changes in their properties. - __Simple configuration__: hook binding definition is a JSON or YAML document on script's stdout. - __Validating webhook machinery__: hook can handle validating for Kubernetes resources. - __Conversion webhook machinery__: hook can handle version conversion for Kubernetes resources. **Contents**: * [Quickstart](#quickstart) * [Build an image with your hooks](#build-an-image-with-your-hooks) * [Create RBAC objects](#create-rbac-objects) * [Install shell-operator in a cluster](#install-shell-operator-in-a-cluster) * [It all comes together](#it-all-comes-together) * [Hook binding types](#hook-binding-types) * [`kubernetes`](#kubernetes) * [`onStartup`](#onstartup) * [`schedule`](#schedule) * [Prometheus target](#prometheus-target) * [Examples and notable users](#examples-and-notable-users) * [Articles & talks](#articles--talks) * [Community](#community) * [License](#license) # Quickstart > You need to have a Kubernetes cluster, and the `kubectl` must be configured to communicate with your cluster. The simplest setup of shell-operator in your cluster consists of these steps: - build an image with your hooks (scripts) - create necessary RBAC objects (for `kubernetes` bindings) - run Pod or Deployment with the built image For more configuration options see [RUNNING](RUNNING.md). ## Build an image with your hooks A hook is a script that, when executed with `--config` option, outputs configuration to stdout in YAML or JSON format. [Learn more](HOOKS.md) about hooks. Let's create a small operator that will watch for all Pods in all Namespaces and simply log the name of a new Pod. `kubernetes` binding is used to tell shell-operator about objects that we want to watch. Create the `pods-hook.sh` file with the following content: ```bash #!/usr/bin/env bash if [[ $1 == "--config" ]] ; then cat < *Note:* hook output is logged with output=stdout label. To clean up a cluster, delete namespace and RBAC objects: ```shell kubectl delete ns example-monitor-pods kubectl delete clusterrole monitor-pods kubectl delete clusterrolebinding monitor-pods ``` This example is also available in /examples: [monitor-pods](examples/101-monitor-pods). # Hook binding types Every hook should respond with JSON or YAML configuration of bindings when executed with `--config` flag. ## kubernetes This binding defines a subset of Kubernetes objects that shell-operator will monitor and a [jq](https://github.com/stedolan/jq/) expression to filter their properties. Read more about `onKubernetesEvent` bindings [here](HOOKS.md#kubernetes). Example of YAML output from `hook --config`: ```yaml configVersion: v1 kubernetes: - name: execute_on_changes_of_namespace_labels kind: Namespace executeHookOnEvent: ["Modified"] jqFilter: ".metadata.labels" ``` > Note: it is possible to watch Custom Defined Resources, just use proper values for `apiVersion` and `kind` fields. > Note: return configuration as JSON is also possible as JSON is a subset of YAML. ## onStartup This binding has only one parameter: order of execution. Hooks are loaded at the start and then hooks with onStartup binding are executed in the order defined by parameter. Read more about `onStartup` bindings [here](HOOKS.md#onstartup). Example `hook --config`: ```yaml configVersion: v1 onStartup: 10 ``` ## schedule This binding is used to execute hooks periodically. A schedule can be defined with a granularity of seconds. Read more about `schedule` bindings [here](HOOKS.md#schedule). Example `hook --config` with 2 schedules: ```yaml configVersion: v1 schedule: - name: "every 10 min" crontab: "*/10 * * * *" allowFailure: true - name: "Every Monday at 8:05" crontab: "5 8 * * 1" queue: mondays ``` # Prometheus target Shell-operator provides a `/metrics` endpoint. More on this in [METRICS](METRICS.md) document. # Examples and notable users More examples of how you can use shell-operator are available in the [examples](examples/) directory. Prominent shell-operator use cases include: * [Deckhouse](https://deckhouse.io/) Kubernetes platform where both projects, shell-operator and addon-operator, are used as the core technology to configure & extend K8s features; * KubeSphere Kubernetes platform's [installer](https://github.com/kubesphere/ks-installer); * [Kafka DevOps solution](https://github.com/confluentinc/streaming-ops) from Confluent. Please find out & share more examples in [Show & tell discussions](https://github.com/flant/shell-operator/discussions/categories/show-and-tell). # Articles & talks Shell-operator has been presented during KubeCon + CloudNativeCon Europe 2020 Virtual (Aug'20). Here is the talk called "Go? Bash! Meet the shell-operator": * [YouTube video](https://www.youtube.com/watch?v=we0s4ETUBLc); * [text summary](https://medium.com/flant-com/meet-the-shell-operator-kubecon-36c14ba2f8fe); * [slides](https://speakerdeck.com/flant/go-bash-meet-the-shell-operator). Official publications on shell-operator: * "[shell-operator v1.0.0: the long-awaited release of our tool to create Kubernetes operators](https://blog.flant.com/shell-operator-v1-release-for-kubernetes-operators/)" (Apr'21); * "[shell-operator & addon-operator news: hooks as admission webhooks, Helm 3, OpenAPI, Go hooks, and more!](https://blog.flant.com/shell-operator-addon-operator-v1-rc1-changes/)" (Feb'21); * "[Kubernetes operators made easy with shell-operator: project status & news](https://blog.flant.com/kubernetes-operators-made-easy-with-shell-operator-project-status-news/)" (Jul'20); * "[Announcing shell-operator to simplify creating of Kubernetes operators](https://blog.flant.com/announcing-shell-operator-to-simplify-creating-of-kubernetes-operators/)" (May'19). Other languages: * Chinese: "[介绍一个不太小的工具:Shell Operator](https://blog.fleeto.us/post/shell-operator/)"; "[使用shell-operator实现Operator](https://cloud.tencent.com/developer/article/1701733)"; * Dutch: "[Een operator om te automatiseren – Hoe pak je dat aan?](https://www.hcs-company.com/blog/operator-automatiseren-namespace-openshift)"; * Russian: "[shell-operator v1.0.0: долгожданный релиз нашего проекта для Kubernetes-операторов](https://habr.com/ru/company/flant/blog/551456/)"; "[Представляем shell-operator: создавать операторы для Kubernetes стало ещё проще](https://habr.com/ru/company/flant/blog/447442/)". # Community Please feel free to reach developers/maintainers and users via [GitHub Discussions](https://github.com/flant/shell-operator/discussions) for any questions regarding shell-operator. You're also welcome to follow [@flant_com](https://twitter.com/flant_com) to stay informed about all our Open Source initiatives. # License Apache License 2.0, see [LICENSE](LICENSE).