Extend the Kubernetes API with Elixir.
Bonny make it easy to create Kubernetes Operators, Controllers, and Custom Schedulers.
If Kubernetes CRDs and controllers are new to you, read up on the terminology.
Important! These tutorials are for an older version of Bonny, but the add/1
, modify/1
, and delete/1
APIs are the same, as well as a new reconcile/1
function. Additionally a k8s has been added!
Feel free to message me on twitter if you need any help!
Bonny can be installed by adding bonny
to your list of dependencies in mix.exs
:
def deps do
[
{:bonny, "~> 0.4"}
]
end
Bonny uses the k8s client under the hood.
The only configuration parameters required are :bonny
controllers
and a :k8s
cluster:
config :k8s,
clusters: %{
default: %{ # `default` here must match `cluster_name` below
conn: "~/.kube/config"
}
}
config :bonny,
# Add each CRD Controller module for this operator to load here
# Defaults to none. This *must* be set.
controllers: [
MyApp.Controllers.V1.WebServer,
MyApp.Controllers.V1.Database,
MyApp.Controllers.V1.Memcached
],
# K8s.Cluster to use, defaults to :default
cluster_name: :default,
# The namespace to watch for Namespaced CRDs.
# Defaults to "default". `:all` for all namespaces
# Also configurable via environment variable `BONNY_POD_NAMESPACE`
namespace: "default",
# Set the Kubernetes API group for this operator.
# This can be overwritten using the @group attribute of a controller
group: "your-operator.example.com",
# Name must only consist of only lowercase letters and hyphens.
# Defaults to hyphenated mix app name
operator_name: "your-operator",
# Name must only consist of only lowercase letters and hyphens.
# Defaults to hyphenated mix app name
service_account_name: "your-operator",
# Labels to apply to the operator's resources.
labels: %{
"kewl": "true"
},
# Operator deployment resources. These are the defaults.
resources: %{
limits: %{cpu: "200m", memory: "200Mi"},
requests: %{cpu: "200m", memory: "200Mi"}
}
When configuring bonny to run in your cluster the mix bonny.gen.manifest
command will generate a service account for you. To use that service account configure the k8s
library like the following:
config :k8s,
clusters: %{
default: %{}
}
This will add a cluster named default
. When no configuration information is provided, the k8s
library will use the service account of the pod.
Running an operator outside of Kubernetes is not recommended for production use, but can be very useful when testing.
To start your operator and connect it to an existing cluster, one must first:
# config.exs
config :k8s,
clusters: %{
default: %{
conn: "~/.kube/config"
}
}
CustomResourceDefinition
, ClusterRole
, ClusterRoleBinding
and ServiceAccount
.mix bonny.gen.manifest
and install it using kubectl kubectl apply -f manifest.yaml
Now you are ready to run your operator
iex -S mix
There are a number of generators to help create a Kubernetes operator.
mix help | grep bonny
An operator can have multiple controllers. Each controller handles the lifecycle of a custom resource.
By default controllers are generated in the V1
version scope.
mix bonny.gen.controller Widget widgets
You can specify the version flag to create a new version of a controller. Bonny will dispatch the controller for the given version. So old versions of resources can live alongside new versions.
mix bonny.gen.controller Widget widgets --version v2alpha1
Note: The one restriction with versions is that they will be camelized into a module name.
Open up your controller and add functionality for your resource's lifecycles:
Each controller can create multiple resources.
For example, a todo app controller could deploy a Deployment
and a Service
.
Your operator can also have multiple controllers if you want to support multiple resources in your operator!
Check out the two test controllers:
The following command will generate a dockerfile for your operator. This will need to be pushed to a docker repository that your Kubernetes cluster can access.
Again, this Dockerfile is for your operator, not for the pods your operator may deploy.
You can skip this step when developing by running your operator external to the cluster.
mix bonny.gen.dockerfile
export BONNY_IMAGE=YOUR_IMAGE_NAME_HERE
docker build -t ${BONNY_IMAGE} .
docker push ${BONNY_IMAGE}:latest
This will generate the entire manifest for this operator including:
The operator manifest generator requires the image
flag to be passed if you plan to deploy the operator in your cluster. This is the docker image URL of your operators docker image created by mix bonny.gen.docker
above.
mix bonny.gen.manifest --image ${BONNY_IMAGE}
You may omit the --image
flag if you want to generate a manifest without the deployment so that you can develop locally running the operator outside of the cluster.
Note: YAML output is JSON formatted YAML. Sorry, elixirland isn't fond of YAML :D
By default the manifest will generate the service account and deployment in the "default" namespace.
To set the namespace explicitly:
mix bonny.gen.manifest --out - -n test
Alternatively you can apply it directly to kubectl:
mix bonny.gen.manifest --out - -n test | kubectl apply -f - -n test
TODO: Need to support validation / OpenAPI.
Bonny uses the telemetry
and notion
library to emit event metrics.
Events: Bonny.Sys.Event.events()
[
[:bonny, :scheduler, :binding, :failed],
[:bonny, :scheduler, :binding, :succeeded],
[:bonny, :scheduler, :nodes, :fetch, :failed],
[:bonny, :scheduler, :nodes, :fetch, :succeeded],
[:bonny, :scheduler, :pods, :fetch, :failed],
[:bonny, :scheduler, :pods, :fetch, :succeeded],
[:bonny, :reconciler, :genserver, :down],
[:bonny, :reconciler, :reconcile, :failed],
[:bonny, :reconciler, :reconcile, :succeeded],
[:bonny, :reconciler, :run, :started],
[:bonny, :reconciler, :fetch, :failed],
[:bonny, :reconciler, :fetch, :succeeded],
[:bonny, :reconciler, :initialized],
[:bonny, :watcher, :genserver, :down],
[:bonny, :watcher, :chunk, :received],
[:bonny, :watcher, :watch, :timedout],
[:bonny, :watcher, :watch, :failed],
[:bonny, :watcher, :watch, :finished],
[:bonny, :watcher, :watch, :succeeded],
[:bonny, :watcher, :watch, :started],
[:bonny, :watcher, :initialized]
]
A custom resource is an extension of the Kubernetes API that is not necessarily available on every Kubernetes cluster. In other words, it represents a customization of a particular Kubernetes installation.
CRD Custom Resource Definition:
The CustomResourceDefinition API resource allows you to define custom resources. Defining a CRD object creates a new custom resource with a name and schema that you specify. The Kubernetes API serves and handles the storage of your custom resource.
A custom controller is a controller that users can deploy and update on a running cluster, independently of the cluster’s own lifecycle. Custom controllers can work with any kind of resource, but they are especially effective when combined with custom resources. The Operator pattern is one example of such a combination. It allows developers to encode domain knowledge for specific applications into an extension of the Kubernetes API.
A set of application specific controllers deployed on Kubernetes and managed via kubectl and the Kubernetes API.
mix test
近日大一期末临近,处在计算机大类专业的我也即将面临专业分流。在软件工程这个新的开始前,未来的系主任组织了一次软件分享会,通过大二、大三学生向大一的我们的作品展示,提前让我们了解自制软件如现流行软件的不同,以及软件制作有哪些方面需要注意的。 我投票的作品叫Bonny,是一个面向铁大学子的校园互助的app。接下来就基于这个app分享几点软件使用体验。 第一,UI界面。一个良好的UI界面是
bonny-erp 链接:http://www.cnblogs.com/bonny.wong/articles/96778.html 来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/312079/viewspace-245134/,如需转载,请注明出处,否则将追究法律责任。 转载于:http://blog.itpub.net/312079/viewspace-24
在这上面感觉真好。呵呵!祝所有博客园的网友新年快乐,万事如意! 转载于:https://www.cnblogs.com/didasoft/archive/2005/02/17/105151.html
在上周四(即6月13日)下午,应王建民老师的邀请,我参观了学长学姐们的软件设计评比以及专业交流的活动,看到了形形色色学长学姐设计出的软件我觉得非常有趣,并对学长学姐们设计的软件的种类与功能感到由衷的钦佩。虽然这些软件都还不是特别成熟,都有着各自的一些不足之处与bug,但在我这个学弟看来,能构思出软件的主要作用并成功设计出这些软件已经非常了不起了。 在27个团队项目中
Bonny校园是一款集校园表白墙、失物招领处和二手市场集一体的一款校园app,旨在帮助大学生解决校内的生活问题。这款app功能比较齐全,表白墙内含有许多有趣的信息展示,失物招领处内可以详细的展示捡到东西的地址、时间、图片以及联系方式,二手市场内也有很详细的信息展示。在“喜欢”一栏里里可以看到其他用户发表的各种内容,也可以发表一些自己想要展示的东西。Bonny校园app的体验感总体来说还算不错,但是