开源软件名称(OpenSource Name):flant/shell-operator开源软件地址(OpenSource Url):https://github.com/flant/shell-operator开源编程语言(OpenSource Language):Go 98.4%开源软件介绍(OpenSource Introduction):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 Shell-operator is used as a base for more advanced addon-operator that supports Helm charts and value storages. Shell-operator provides:
Contents:
Quickstart
The simplest setup of shell-operator in your cluster consists of these steps:
For more configuration options see RUNNING. Build an image with your hooksA hook is a script that, when executed with Let's create a small operator that will watch for all Pods in all Namespaces and simply log the name of a new Pod.
#!/usr/bin/env bash
if [[ $1 == "--config" ]] ; then
cat <<EOF
configVersion: v1
kubernetes:
- apiVersion: v1
kind: Pod
executeHookOnEvent: ["Added"]
EOF
else
podName=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH)
echo "Pod '${podName}' added"
fi Make the chmod +x pods-hook.sh You can use a prebuilt image flant/shell-operator:latest with Create the following FROM flant/shell-operator:latest
ADD pods-hook.sh /hooks Build an image (change image tag according to your Docker registry): docker build -t "registry.mycompany.com/shell-operator:monitor-pods" . Push image to the Docker registry accessible by the Kubernetes cluster: docker push registry.mycompany.com/shell-operator:monitor-pods Create RBAC objectsWe need to watch for Pods in all Namespaces. That means that we need specific RBAC definitions for shell-operator: kubectl create namespace example-monitor-pods
kubectl create serviceaccount monitor-pods-acc --namespace example-monitor-pods
kubectl create clusterrole monitor-pods --verb=get,watch,list --resource=pods
kubectl create clusterrolebinding monitor-pods --clusterrole=monitor-pods --serviceaccount=example-monitor-pods:monitor-pods-acc Install shell-operator in a clusterShell-operator can be deployed as a Pod. Put this manifest into the apiVersion: v1
kind: Pod
metadata:
name: shell-operator
spec:
containers:
- name: shell-operator
image: registry.mycompany.com/shell-operator:monitor-pods
imagePullPolicy: Always
serviceAccountName: monitor-pods-acc Start shell-operator by applying a kubectl -n example-monitor-pods apply -f shell-operator-pod.yaml It all comes togetherLet's deploy a kubernetes-dashboard to trigger kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended.yaml Now run
To clean up a cluster, delete namespace and RBAC objects: 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. Hook binding typesEvery hook should respond with JSON or YAML configuration of bindings when executed with kubernetesThis binding defines a subset of Kubernetes objects that shell-operator will monitor and a jq expression to filter their properties. Read more about Example of YAML output from configVersion: v1
kubernetes:
- name: execute_on_changes_of_namespace_labels
kind: Namespace
executeHookOnEvent: ["Modified"]
jqFilter: ".metadata.labels"
onStartupThis 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 Example configVersion: v1
onStartup: 10 scheduleThis binding is used to execute hooks periodically. A schedule can be defined with a granularity of seconds. Read more about Example configVersion: v1
schedule:
- name: "every 10 min"
crontab: "*/10 * * * *"
allowFailure: true
- name: "Every Monday at 8:05"
crontab: "5 8 * * 1"
queue: mondays Prometheus targetShell-operator provides a Examples and notable usersMore examples of how you can use shell-operator are available in the examples directory. Prominent shell-operator use cases include:
Please find out & share more examples in Show & tell discussions. Articles & talksShell-operator has been presented during KubeCon + CloudNativeCon Europe 2020 Virtual (Aug'20). Here is the talk called "Go? Bash! Meet the shell-operator": Official publications on shell-operator:
Other languages:
CommunityPlease feel free to reach developers/maintainers and users via GitHub Discussions for any questions regarding shell-operator. You're also welcome to follow @flant_com to stay informed about all our Open Source initiatives. LicenseApache License 2.0, see LICENSE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论